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.
Deque
Double-ended queue backed by a ring buffer: O(1) amortised at both ends and O(1) index access. Unlike List there is no cursor; unlike Vector, AddFront and RemoveFront are O(1).
Operations
AddBack #
Adds a value to the back
method : public : AddBack(value:H) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| value | H | value to add |
Example
d := Collection.Deque->New()<String>;
d->AddBack("a"); d->AddBack("b");
d->Back()->PrintLine(); # bAddFront #
Adds a value to the front
method : public : AddFront(value:H) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| value | H | value to add |
Example
d := Collection.Deque->New()<String>;
d->AddBack("b"); d->AddFront("a");
d->Front()->PrintLine(); # aBack #
Gets the back value without removing it
method : public : Back() ~ HReturn
| Type | Description |
|---|---|
| H | the value, or Nil if empty |
Example
d := Collection.Deque->New()<String>;
d->AddBack("a"); d->AddBack("b");
d->Back()->PrintLine(); # bFront #
Gets the front value without removing it
method : public : Front() ~ HReturn
| Type | Description |
|---|---|
| H | the value, or Nil if empty |
Example
d := Collection.Deque->New()<String>;
d->AddBack("a");
d->Front()->PrintLine(); # aGet #
Gets a value by position, 0 being the front
method : public : Get(index:Int) ~ HParameters
| Name | Type | Description |
|---|---|---|
| index | Int | position |
Return
| Type | Description |
|---|---|
| H | the value, or Nil for a bad index |
Example
d := Collection.Deque->New()<String>;
d->AddBack("a"); d->AddBack("b");
d->Get(1)->PrintLine(); # bIsEmpty #
Checks for no values
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty |
New # constructor
Default constructor
New()Example
d := Collection.Deque->New()<String>;
d->AddBack("b");
d->AddFront("a");
d->Size()->PrintLine(); # 2RemoveBack #
Removes the back value
method : public : RemoveBack() ~ HReturn
| Type | Description |
|---|---|
| H | the value, or Nil if empty |
Example
d := Collection.Deque->New()<String>;
d->AddBack("a"); d->AddBack("b");
d->RemoveBack()->PrintLine(); # bRemoveFront #
Removes the front value
method : public : RemoveFront() ~ HReturn
| Type | Description |
|---|---|
| H | the value, or Nil if empty |
Example
d := Collection.Deque->New()<String>;
d->AddBack("a"); d->AddBack("b");
d->RemoveFront()->PrintLine(); # aSet #
Replaces a value by position
method : public : Set(value:H, index:Int) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | H | new value |
| index | Int | position |
Return
| Type | Description |
|---|---|
| Bool | true if set, false for a bad index |
Example
d := Collection.Deque->New()<String>;
d->AddBack("a");
d->Set("z", 0)->PrintLine(); # trueToArray #
Copies the values, front first, into an array
method : public : ToArray() ~ H[]Return
| Type | Description |
|---|---|
| H[] | array of Size() values |
Example
d := Collection.Deque->New()<String>;
d->AddBack("b"); d->AddFront("a");
d->ToArray()[0]->PrintLine(); # a