Bundle Generic collections library: Vector (dynamic array), Map (hash map), Set, MultiMap, Stack, Queue, and Pair. Provides typed iteration, sorting, filtering, and functional operations (Reduce, Any, All). Compile with -lib gen_collect.
SetHash
Unordered set of generic objects
# insert elements
set_hash := Collection.SetHash->New()<String>;
set_hash->Insert("San Francisco");
set_hash->Insert("Oakland");
set_hash->Insert("East Bay");
# get size
set_hash->Size()->PrintLine();
# get value by key
set_hash->Has("Oakland")->PrintLine();Operations
Empty #
Clears the set
method : public : Empty() ~ NilExample
sh := Collection.SetHash->New()<String>;
sh->Insert("item");
sh->Empty();
sh->IsEmpty()->PrintLine(); # trueGetKeys #
Get a collection of keys
method : public : GetKeys() ~ Vector<K>Return
| Type | Description |
|---|---|
| Vector<K> | vector of keys |
Example
sh := Collection.SetHash->New()<String>;
sh->Insert("x"); sh->Insert("y");
keys := sh->GetKeys()<String>;
keys->Size()->PrintLine(); # 2Has #
Checks for key in set
method : public : Has(key:K) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | K | search key |
Return
| Type | Description |
|---|---|
| Bool | true if found, false otherwise |
Example
sh := Collection.SetHash->New()<String>;
sh->Insert("present");
sh->Has("present")->PrintLine(); # true
sh->Has("absent")->PrintLine(); # falseInsert #
Inserts a key into the set
method : public : Insert(key:K) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| key | K | key |
Example
sh := Collection.SetHash->New()<String>;
sh->Insert("blue");
sh->Has("blue")->PrintLine(); # trueIsEmpty #
Checks to see if the set is empty
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty, false otherwise |
Example
sh := Collection.SetHash->New()<String>;
sh->IsEmpty()->PrintLine(); # true
sh->Insert("z");
sh->IsEmpty()->PrintLine(); # falseNew # constructor
Default constructor
New()Example
sh := Collection.SetHash->New()<String>;
sh->Insert("hello");
sh->Size()->PrintLine(); # 1Remove #
Removes a key from the set
method : public : Remove(key:K) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | K | key for value to remove |
Return
| Type | Description |
|---|---|
| Bool | true if removed, false otherwise |
Example
sh := Collection.SetHash->New()<String>;
sh->Insert("tmp");
sh->Remove("tmp")->PrintLine(); # true
sh->Has("tmp")->PrintLine(); # falseSize #
Size of set
method : public : Size() ~ IntReturn
| Type | Description |
|---|---|
| Int | number of elements |
Example
sh := Collection.SetHash->New()<String>;
sh->Insert("a"); sh->Insert("b");
sh->Size()->PrintLine(); # 2ToString #
Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.
method : public : ToString() ~ StringReturn
| Type | Description |
|---|---|
| String | string representation |
Example
sh := Collection.SetHash->New()<String>;
sh->Insert("m"); sh->Insert("n");
sh->ToString()->PrintLine();