v2026.11.3
All Bundles
Bundle

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.

OrderedHash

Insertion-ordered hash: key to value with O(1) expected Insert, Find, Has and Remove, and iteration in the order keys were first inserted. Updating an existing key keeps its position. A Hash is unordered and a Map is sorted by key; use this when the order of arrival matters.

Operations

Each #

Calls a function for every entry in insertion order

method : public : Each(f:(K,V)~Nil) ~ OrderedHash<K,V>

Parameters

NameTypeDescription
f(K,V)~Nilfunction taking the key and value

Return

TypeDescription
OrderedHash<K,V>this hash

Example

h := Collection.OrderedHash->New()<String, IntRef>;
h->Insert("a", IntRef->New(1));
h->Each(\(k, v) => k->PrintLine());

Empty #

Removes every entry

method : public : Empty() ~ Nil

Find #

Finds the value for a key

method : public : Find(key:K) ~ V

Parameters

NameTypeDescription
keyKkey

Return

TypeDescription
Vvalue, or Nil if absent

FirstKey #

Gets the oldest key (the first one inserted that is still present)

method : public : FirstKey() ~ K

Return

TypeDescription
Kkey, or Nil if empty

GetKeys #

Gets the keys in insertion order

method : public : GetKeys() ~ Vector<K>

Return

TypeDescription
Vector<K>vector of keys

GetValues #

Gets the values in insertion order of their keys

method : public : GetValues() ~ Vector<V>

Return

TypeDescription
Vector<V>vector of values

Has #

Checks whether a key is present

method : public : Has(key:K) ~ Bool

Parameters

NameTypeDescription
keyKkey

Return

TypeDescription
Booltrue if present

Insert #

Inserts a key or updates its value; a new key goes last, an existing key keeps its place

method : public : Insert(key:K, value:V) ~ Nil

Parameters

NameTypeDescription
keyKkey
valueVvalue

Example

h := Collection.OrderedHash->New()<String, IntRef>;
h->Insert("a", IntRef->New(1));
h->Insert("a", IntRef->New(5));
h->Find("a")->Get()->PrintLine(); # 5
h->Size()->PrintLine();           # 1

IsEmpty #

Checks for no entries

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty

LastKey #

Gets the newest key

method : public : LastKey() ~ K

Return

TypeDescription
Kkey, or Nil if empty

New # constructor

Default constructor

New()

Example

h := Collection.OrderedHash->New()<String, IntRef>;
h->Insert("b", IntRef->New(2)); h->Insert("a", IntRef->New(1));
h->GetKeys()->Get(0)->PrintLine(); # b

Remove #

Removes a key

method : public : Remove(key:K) ~ Bool

Parameters

NameTypeDescription
keyKkey

Return

TypeDescription
Booltrue if it was present

Example

h := Collection.OrderedHash->New()<String, IntRef>;
h->Insert("a", IntRef->New(1));
h->Remove("a")->PrintLine(); # true

RemoveFirst #

Removes the oldest key, as a first-in first-out cache or queue-with-lookup would

method : public : RemoveFirst() ~ K

Return

TypeDescription
Kthe removed key, or Nil if empty

Size #

Gets the number of entries

method : public : Size() ~ Int

Return

TypeDescription
Intsize