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.
Queue
Queue of generics
Example
# insert elements
queue := Collection.Queue->New()<String>;
queue->AddFront("San Francisco");
queue->AddBack("Oakland");
queue->AddBack("East Bay");
queue->AddBack("Mountain View");
# remove element
queue->RemoveBack();
# get size
queue->Size()->PrintLine();
# get value by key
queue->Back()->PrintLine();
queue->Front()->PrintLine();Operations
AddBack #
Adds a value to the back of the queue
method : public : AddBack(value:H) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| value | H | value to add |
Example
queue := Collection.Queue->New()<String>;
queue->AddBack("first");
queue->AddBack("second");
queue->Back()->PrintLine(); # secondAddFront #
Adds a value to the front of the queue
method : public : AddFront(value:H) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| value | H | value to add |
Example
queue := Collection.Queue->New()<String>;
queue->AddBack("middle");
queue->AddFront("head");
queue->Front()->PrintLine(); # headBack #
Get the value from the back of the queue
method : public : Back() ~ HReturn
| Type | Description |
|---|---|
| H | head value, Nil if queue is empty |
Example
queue := Collection.Queue->New()<String>;
queue->AddBack("first");
queue->AddBack("last");
queue->Back()->PrintLine(); # lastEmpty #
Clears the queue
method : public : Empty() ~ NilExample
queue := Collection.Queue->New()<String>;
queue->AddBack("a");
queue->Empty();
queue->IsEmpty()->PrintLine(); # trueFront #
Get the value from the front of the queue
method : public : Front() ~ HReturn
| Type | Description |
|---|---|
| H | head value, Nil if queue is empty |
Example
queue := Collection.Queue->New()<String>;
queue->AddBack("first");
queue->AddBack("last");
queue->Front()->PrintLine(); # firstIsEmpty #
Checks to see if the queue is empty
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty, false otherwise |
Example
queue := Collection.Queue->New()<String>;
queue->IsEmpty()->PrintLine(); # true
queue->AddBack("x");
queue->IsEmpty()->PrintLine(); # falseNew # constructor
Default constructor
New()Example
queue := Collection.Queue->New()<String>;
queue->AddBack("first");
queue->AddBack("second");
queue->Front()->PrintLine(); # firstRemoveBack #
Removes a value from the back of the queue
method : public : RemoveBack() ~ HReturn
| Type | Description |
|---|---|
| H | value removed |
Example
queue := Collection.Queue->New()<String>;
queue->AddBack("alpha");
queue->AddBack("beta");
queue->RemoveBack()->PrintLine(); # beta
queue->Back()->PrintLine(); # alphaRemoveFront #
Removes a value from the front of the queue
method : public : RemoveFront() ~ HReturn
| Type | Description |
|---|---|
| H | value removed |
Example
queue := Collection.Queue->New()<String>;
queue->AddBack("first");
queue->AddBack("second");
queue->RemoveFront()->PrintLine(); # first
queue->Front()->PrintLine(); # secondSize #
Size of queue
method : public : Size() ~ IntReturn
| Type | Description |
|---|---|
| Int | size of queue |
Example
queue := Collection.Queue->New()<String>;
queue->AddBack("a");
queue->AddBack("b");
queue->Size()->PrintLine(); # 2ToArray #
Converts the queue into an object array
method : public : ToArray() ~ H[]Return
| Type | Description |
|---|---|
| H[] | object array |
Example
queue := Collection.Queue->New()<String>;
queue->AddBack("a");
queue->AddBack("b");
arr := queue->ToArray();
arr[0]->PrintLine(); # aToString #
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
queue := Collection.Queue->New()<String>;
queue->AddBack("a");
queue->AddBack("b");
queue->ToString()->PrintLine(); # [a,b]