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.
HashSet
Hash-based set for O(1) membership testing without storing values
Example
set := Collection.HashSet->New()<IntRef>;
set->Add(IntRef->New(1));
set->Add(IntRef->New(2));
set->Add(IntRef->New(3));
set->Has(IntRef->New(2))->PrintLine(); # true
set->Has(IntRef->New(5))->PrintLine(); # false
set->Remove(IntRef->New(2));
set->Has(IntRef->New(2))->PrintLine(); # falseOperations
Add #
Adds a value to the set
method : public : Add(value:H) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | H | value to add |
Return
| Type | Description |
|---|---|
| Bool | true if added, false if already exists |
Example
set := Collection.HashSet->New()<String>;
set->Add("apple")->PrintLine(); # true
set->Add("apple")->PrintLine(); # false (duplicate)
set->Size()->PrintLine(); # 1Empty #
Clears the set
method : public : Empty() ~ NilExample
set := Collection.HashSet->New()<String>;
set->Add("a");
set->Empty();
set->IsEmpty()->PrintLine(); # trueHas #
Checks if a value exists in the set
method : public : Has(value:H) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | H | value to check |
Return
| Type | Description |
|---|---|
| Bool | true if found, false otherwise |
Example
set := Collection.HashSet->New()<String>;
set->Add("hello");
set->Has("hello")->PrintLine(); # true
set->Has("world")->PrintLine(); # falseIsEmpty #
Checks if set is empty
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty, false otherwise |
Example
set := Collection.HashSet->New()<String>;
set->IsEmpty()->PrintLine(); # true
set->Add("x");
set->IsEmpty()->PrintLine(); # falseNew # constructor
Default constructor
New()Example
set := Collection.HashSet->New()<String>;
set->Add("apple");
set->Add("banana");
set->Size()->PrintLine(); # 2Remove #
Removes a value from the set
method : public : Remove(value:H) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | H | value to remove |
Return
| Type | Description |
|---|---|
| Bool | true if removed, false if not found |
Example
set := Collection.HashSet->New()<String>;
set->Add("hello");
set->Remove("hello")->PrintLine(); # true
set->Has("hello")->PrintLine(); # falseSize #
Size of set
method : public : Size() ~ IntReturn
| Type | Description |
|---|---|
| Int | number of elements |
Example
set := Collection.HashSet->New()<String>;
set->Add("a");
set->Add("b");
set->Size()->PrintLine(); # 2ToArray #
Gets all values as an array
method : public : ToArray() ~ H[]Return
| Type | Description |
|---|---|
| H[] | array of values |
Example
set := Collection.HashSet->New()<String>;
set->Add("p");
set->Add("q");
arr := set->ToArray();
arr->Size()->PrintLine(); # 2