Hash-based set of keys parameterized by a key schema.
HashSet
Construct with the key schema before the type name: Key HashSet, for example Int32 HashSet.
HashSet
(keySchema -- set) Constructs an empty owning set from a key schema.- Stored keys must support construction. Text is not a constructible stored item here; use
Stringfor owned text.
Fields
SCHEMA_NAME: static Text schema-name field built from the key schema name.HASH_SET: static empty-Tuple marker.Key: static NIL reference descriptor for the key schema.
A new HashSet is empty. An immutable set source is copied using contained assignment operations; a mutable set can be moved, leaving the source empty. Destroying the set destroys its owned arrays and keys, not objects merely referenced by contained reference fields.
A HashSet stores its keys in a HashTable, whose key requirements and iteration order apply. Reacquire key views and iterators after any insertion or erasure, and after clear, release, assignment, move, or destruction.
Methods
clear
(--) Removes stored keys and sets the item count to zero.- The outer bucket array retains its reserved allocation; stored keys are destroyed.
empty
(-- cond) Reports whether the set has no stored keys.- On a nonempty set, a missing key reports
Erasing unexisting element!and exits with status 2; on an empty set it does not.
predicatehas effect(key -- cond);keyis an immutable view of a stored key.
- With DEBUG enabled, inserting an existing key reports
The key is already in the HashTableand exits with status 2; with DEBUG disabled, duplicate keys are accepted. keyis copied or moved according to its view and construction support: a mutable managed key can be moved from, an immutable key is copied, and contained references retain aliasing.
iter
(-- iter) Returns an iterator of stored keys.nexthas effect(-- item valid); it yields immutable key views.
release
(--) Releases bucket storage and sets the item count to zero.size
(-- count) Returns the number of stored keys.Examples
Example: eraseIf and iter
After four inserts, eraseIf removes the even keys, and iter visits the two that remain.
"HashSet" use
"String" use
"algorithm" use
"control" use
{} Int32 {} [
numbers: Int32 HashSet;
1 @numbers.insert
2 @numbers.insert
3 @numbers.insert
4 @numbers.insert
[2 mod 0 =] @numbers.eraseIf
sum: 0;
numbers.iter [sum + @sum set] each
("size=" numbers.size LF
"sum=" sum LF
"has2=" 2 numbers.contains LF) printList
0
] "main" exportFunction
Expected Output
size=2
sum=4
has2=FALSE