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.
Set
Ordered set of generic objects
Example
# insert elements
set := Collection.Set->New()<String>;
set->Insert("San Francisco");
set->Insert("Oakland");
set->Insert("East Bay");
# get size
set->Size()->PrintLine();
# get value by key
set->Has("Oakland")->PrintLine();Operations
Empty #
Clears the set
method : public : Empty() ~ NilExample
set := Collection.Set->New()<String>;
set->Insert("item");
set->Empty();
set->IsEmpty()->PrintLine(); # trueGetKeys #
Get a collection of keys
method : public : GetKeys() ~ Vector<K>Return
| Type | Description |
|---|---|
| Vector<K> | vector of keys |
Example
set := Collection.Set->New()<String>;
set->Insert("a"); set->Insert("b");
keys := set->GetKeys()<String>;
each(k := keys) { k->PrintLine(); }Has #
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
set := Collection.Set->New()<String>;
set->Insert("found");
set->Has("found")->PrintLine(); # true
set->Has("missing")->PrintLine(); # falseInsert #
Inserts a key into the set
method : public : Insert(key:K) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| key | K | key |
Example
set := Collection.Set->New()<String>;
set->Insert("apple");
set->Insert("apple"); # duplicate ignored
set->Size()->PrintLine(); # 1IsEmpty #
Checks to see if the set is empty
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty, false otherwise |
Example
set := Collection.Set->New()<String>;
set->IsEmpty()->PrintLine(); # true
set->Insert("z");
set->IsEmpty()->PrintLine(); # falseNew # constructor
Default constructor
New()Example
set := Collection.Set->New()<String>;
set->Insert("hello");
set->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
set := Collection.Set->New()<String>;
set->Insert("go");
set->Remove("go")->PrintLine(); # true
set->Has("go")->PrintLine(); # falseSize #
Size of map
method : public : Size() ~ IntReturn
| Type | Description |
|---|---|
| Int | size of queue |
Example
set := Collection.Set->New()<String>;
set->Insert("a"); set->Insert("b"); set->Insert("c");
set->Size()->PrintLine(); # 3ToString #
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
set := Collection.Set->New()<String>;
set->Insert("x"); set->Insert("y");
set->ToString()->PrintLine(); # [x,y]