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.
PriorityMap
Indexed min-priority queue: each key is held once with a Float priority that can be lowered or raised later (decrease-key), which the plain Heap cannot do. Push of a present key updates it. Push, Pop, Remove and priority updates are O(log n); Has, Priority and Peek are O(1) expected. The smallest priority comes out first.
Operations
Has #
Checks whether a key is present
method : public : Has(key:T) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | T | key |
Return
| Type | Description |
|---|---|
| Bool | true if present |
New # constructor
Default constructor
New()Example
q := Collection.PriorityMap->New()<String>;
q->Push("far", 9.0); q->Push("near", 1.0);
q->Pop()->PrintLine(); # nearPeek #
Gets the key with the smallest priority without removing it
method : public : Peek() ~ TReturn
| Type | Description |
|---|---|
| T | key, or Nil if empty |
PeekPriority #
Gets the smallest priority
method : public : PeekPriority() ~ FloatReturn
| Type | Description |
|---|---|
| Float | priority, 0.0 if empty |
Pop #
Removes and returns the key with the smallest priority
method : public : Pop() ~ TReturn
| Type | Description |
|---|---|
| T | key, or Nil if empty |
Example
q := Collection.PriorityMap->New()<String>;
q->Push("b", 2.0); q->Push("a", 1.0);
q->Pop()->PrintLine(); # aPriority #
Gets the priority of a key
method : public : Priority(key:T) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| key | T | key |
Return
| Type | Description |
|---|---|
| Float | priority, 0.0 if the key is absent (use Has to tell) |
Push #
Adds a key, or changes its priority if it is already present
method : public : Push(key:T, priority:Float) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| key | T | key (Nil is ignored) |
| priority | Float | priority, smaller comes out first |
Example
q := Collection.PriorityMap->New()<String>;
q->Push("a", 5.0);
q->Push("a", 2.0); # decrease-key
q->Priority("a")->PrintLine(); # 2