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.
BiMap
Bidirectional map: every key has exactly one value and every value exactly one key, so lookups work in both directions in O(1) expected. Inserting a key or a value that is already present replaces the old pairing. Built from two Hash tables.
Operations
FindKey #
Finds the key paired with a value
method : public : FindKey(value:B) ~ AParameters
| Name | Type | Description |
|---|---|---|
| value | B | value |
Return
| Type | Description |
|---|---|
| A | key, or Nil if absent |
FindValue #
Finds the value paired with a key
method : public : FindValue(key:A) ~ BParameters
| Name | Type | Description |
|---|---|---|
| key | A | key |
Return
| Type | Description |
|---|---|
| B | value, or Nil if absent |
GetKeys #
Gets the keys, order unspecified
method : public : GetKeys() ~ Vector<A>Return
| Type | Description |
|---|---|
| Vector<A> | vector of keys |
GetValues #
Gets the values, order unspecified
method : public : GetValues() ~ Vector<B>Return
| Type | Description |
|---|---|
| Vector<B> | vector of values |
HasKey #
Checks whether a key is present
method : public : HasKey(key:A) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | A | key |
Return
| Type | Description |
|---|---|
| Bool | true if present |
HasValue #
Checks whether a value is present
method : public : HasValue(value:B) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| value | B | value |
Return
| Type | Description |
|---|---|
| Bool | true if present |
Insert #
Pairs a key with a value, first dropping any existing pair that uses that key or that value
method : public : Insert(key:A, value:B) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | A | key |
| value | B | value |
Return
| Type | Description |
|---|---|
| Bool | true if stored, false if either is Nil |
Example
m := Collection.BiMap->New()<String, IntRef>;
m->Insert("a", IntRef->New(1));
m->Insert("b", IntRef->New(1)); # replaces ("a", 1)
m->Size()->PrintLine(); # 1IsEmpty #
Checks for no pairs
method : public : IsEmpty() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if empty |
New # constructor
Default constructor
New()Example
m := Collection.BiMap->New()<String, IntRef>;
m->Insert("one", IntRef->New(1));
m->FindKey(IntRef->New(1))->PrintLine(); # oneRemoveKey #
Removes the pair holding a key
method : public : RemoveKey(key:A) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| key | A | key |
Return
| Type | Description |
|---|---|
| Bool | true if a pair was removed |