Generic collections library: Vector (dynamic array), List (linked list), Map (ordered binary tree, O(log n)), Hash (hash table), Set, HashSet, SetHash, MultiMap, MultiHash, Stack, Queue, and Pair. Provides typed iteration, sorting, filtering, and functional operations (Reduce, Any, All). Compile with -lib gen_collect.
IntSet
Hash set of Int values: open addressing over plain arrays, so nothing is boxed. Every Int is a valid member, including 0 and the Int64 extremes.
Example
set := Collection.IntSet->New();
set->Add(5)->PrintLine(); # true
set->Add(5)->PrintLine(); # false
set->Has(5)->PrintLine(); # true
set->Size()->PrintLine(); # 1Operations
Add # native
Adds a value
method : public : native : Add(value:Int) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | Int | value |
Return
| Type | Description |
|---|---|
| Bool | true if added, false if it was already in the set |
Example
set := Collection.IntSet->New();
set->Add(-1)->PrintLine(); # trueEach #
Calls a function for each value. The function must not change the set.
method : public : Each(f:(Int)~Nil) ~ IntSetParameters
| Name | Type | Description |
|---|---|---|
| f | (Int)~Nil | function called |
Return
| Type | Description |
|---|---|
| IntSet | this set |
Example
set := Collection.IntSet->New();
set->Add(1);
set->Each(\(v) => { v->PrintLine(); });Empty #
Removes every value
method : public : Empty() ~ NilExample
set := Collection.IntSet->New();
set->Add(1);
set->Empty();
set->Size()->PrintLine(); # 0Has # native
Checks for a value
method : public : native : Has(value:Int) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | Int | value |
Return
| Type | Description |
|---|---|
| Bool | true if found, false otherwise |
Example
set := Collection.IntSet->New();
set->Add(3);
set->Has(3)->PrintLine(); # trueInsert #
Inserts a value; the same as Add, for the method name the other sets use
method : public : Insert(value:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| value | Int | value |
Example
set := Collection.IntSet->New();
set->Insert(9);
set->Has(9)->PrintLine(); # trueIsEmpty #
Checks to see if the set is empty
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty, false otherwise |
Example
set := Collection.IntSet->New();
set->IsEmpty()->PrintLine(); # trueNew # constructor
Default constructor
New()Example
set := Collection.IntSet->New();
set->Insert(1);
set->Size()->PrintLine(); # 1New # constructor
Constructor that reserves room for a number of values
New(capacity:Int)Parameters
| Name | Type | Description |
|---|---|---|
| capacity | Int | number of values expected |
Example
set := Collection.IntSet->New(100000);
set->Size()->PrintLine(); # 0Remove # native
Removes a value
method : public : native : Remove(value:Int) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | Int | value |
Return
| Type | Description |
|---|---|
| Bool | true if removed, false if it was not in the set |
Example
set := Collection.IntSet->New();
set->Add(3);
set->Remove(3)->PrintLine(); # trueSize #
Number of values
method : public : Size() ~ IntReturn
| Type | Description |
|---|---|
| Int | number of values |
Example
set := Collection.IntSet->New();
set->Add(1); set->Add(2);
set->Size()->PrintLine(); # 2