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.
Stack
Growable stack of generics (LIFO)
Example
stack := Collection.Stack->New()<IntRef>;
stack->Push(1);
stack->Push(2);
stack->Push(3);
stack->Pop()->PrintLine(); # prints 3
stack->Top()->PrintLine(); # prints 2
stack->Size()->PrintLine(); # prints 2Operations
Empty #
Clears the stack
method : public : Empty() ~ NilExample
stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(5));
stack->Empty();
stack->IsEmpty()->PrintLine(); # trueIsEmpty #
Checks to see if the stack is empty
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty, false otherwise |
Example
stack := Collection.Stack->New()<IntRef>;
stack->IsEmpty()->PrintLine(); # true
stack->Push(IntRef->New(1));
stack->IsEmpty()->PrintLine(); # falseNew # constructor
Default constructor
New()Example
stack := Collection.Stack->New()<String>;
stack->Push("a");
stack->Push("b");
stack->Pop()->PrintLine(); # bPop # native
Pops values from the stack
method : public : native : Pop(n:Int) ~ HParameters
| Name | Type | Description |
|---|---|---|
| n | Int | number of items to pop |
Return
| Type | Description |
|---|---|
| H | popped valued, Nil if stack is empty |
Example
stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(1));
stack->Push(IntRef->New(2));
stack->Push(IntRef->New(3));
stack->Pop(2)->PrintLine(); # 2 (value after skipping 2 items)Pop #
Pops a value from the stack
method : public : Pop() ~ HReturn
| Type | Description |
|---|---|
| H | popped valued, Nil if stack is empty |
Example
stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(7));
stack->Push(IntRef->New(8));
stack->Pop()->PrintLine(); # 8
stack->Size()->PrintLine(); # 1Push #
Pushes a value onto the stack
method : public : Push(value:H) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| value | H | to push |
Example
stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(10));
stack->Push(IntRef->New(20));
stack->Top()->PrintLine(); # 20Size #
Size of stack
method : public : Size() ~ IntReturn
| Type | Description |
|---|---|
| Int | size of stack |
Example
stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(1));
stack->Push(IntRef->New(2));
stack->Size()->PrintLine(); # 2ToArray # native
Converts the stack into an object array
method : public : native : ToArray() ~ H[]Return
| Type | Description |
|---|---|
| H[] | object array |
Example
stack := Collection.Stack->New()<String>;
stack->Push("x");
stack->Push("y");
arr := stack->ToArray();
arr[0]->PrintLine(); # y (top element)ToString #
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
stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(1));
stack->Push(IntRef->New(2));
stack->ToString()->PrintLine(); # [2,1]Top #
Check the top of the stack
method : public : Top() ~ HReturn
| Type | Description |
|---|---|
| H | value on the top of stack, Nil if stack is empty |
Example
stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(42));
stack->Top()->PrintLine(); # 42
stack->Size()->PrintLine(); # 1 (Top does not remove)