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.
Pair
Collection pair that implements Compare interface for use in sorted collections
Example
pair := Collection.Pair->New(IntRef->New(1), "one")<IntRef, String>;
pair->GetFirst()->PrintLine();
pair->GetSecond()->PrintLine();
pair->ToString()->PrintLine();Operations
Compare #
Compares two objects based upon first value
method : public : Compare(rhs:System.Compare) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| rhs | Compare | another pair (the form a sorted collection passes) or the first value of another pair |
Return
| Type | Description |
|---|---|
| Int | 0 if equal, -1 if right-hand side i greater, 1 if left-hand side is greater |
Example
a := Collection.Pair->New(IntRef->New(1), "one")<IntRef, String>;
b := Collection.Pair->New(IntRef->New(2), "two")<IntRef, String>;
a->Compare(b->GetFirst())->PrintLine(); # -1GetFirst #
Gets the first value
method : public : GetFirst() ~ FReturn
| Type | Description |
|---|---|
| F | first value |
Example
pair := Collection.Pair->New(IntRef->New(7), "seven")<IntRef, String>;
pair->GetFirst()->PrintLine(); # 7GetSecond #
Gets the second value
method : public : GetSecond() ~ SReturn
| Type | Description |
|---|---|
| S | second value |
Example
pair := Collection.Pair->New(IntRef->New(3), "three")<IntRef, String>;
pair->GetSecond()->PrintLine(); # threeHashID #
Returns the class default hash ID
method : public : HashID() ~ IntReturn
| Type | Description |
|---|---|
| Int | hash ID |
Example
pair := Collection.Pair->New(IntRef->New(42), "answer")<IntRef, String>;
pair->HashID()->PrintLine();New # constructor
Default constructor
New(first:F, second:S)Parameters
| Name | Type | Description |
|---|---|---|
| first | F | compare object |
| second | S | object |
Example
pair := Collection.Pair->New(IntRef->New(1), "one")<IntRef, String>;
pair->GetFirst()->PrintLine(); # 1
pair->GetSecond()->PrintLine(); # oneSetFirst #
Sets the first value
method : public : SetFirst(first:F) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| first | F | first value |
Example
pair := Collection.Pair->New(IntRef->New(1), "one")<IntRef, String>;
pair->SetFirst(IntRef->New(99));
pair->GetFirst()->PrintLine(); # 99SetSecond #
Sets the second value
method : public : SetSecond(second:S) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| second | S | second value |
Example
pair := Collection.Pair->New(IntRef->New(1), "one")<IntRef, String>;
pair->SetSecond("ONE");
pair->GetSecond()->PrintLine(); # ONEToString #
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
pair := Collection.Pair->New(IntRef->New(5), "five")<IntRef, String>;
pair->ToString()->PrintLine(); # {5,five}