v2026.6.4
All Bundles
Bundle Generic collections library: Vector (dynamic array), Map (hash map), Set, MultiMap, Stack, Queue, and Pair. Provides typed iteration, sorting, filtering, and functional operations (Reduce, Any, All). Compile with -lib gen_collect.

Hash

Hash unordered table of generics

Example

# insert elements
hash := Collection.Hash->New()<IntRef, String>;
hash->Insert(415, "San Francisco");
hash->Insert(510, "Oakland");
hash->Insert(925, "East Bay");

# get size
hash->Size()->PrintLine();

# get value by key
hash->Find(510)->PrintLine();

# get key/values
key_values := hash->GetKeyValues()<Pair<IntRef, String>>;
each(key_value := key_values) {
   key_value->GetFirst()->PrintLine();
};

# get values
values := hash->GetValues()<String>;
each(value := values) {
   value->PrintLine();
};

# check for key
hash->Has(408)->PrintLine();

Operations

Dict # function

Converts a vector pairs to a hash

function : Dict(pairs:Vector<Collection.Tuple.Pair<K,V>>) ~ Hash<K,V>

Parameters

NameTypeDescription
pairsVector<CollectionTuplePair<K,V>>vector of pairs

Return

TypeDescription
Hash<K,V>hashed pairs

Example

pairs := Collection.Vector->New()<Collection.Tuple.Pair<String, IntRef>>;
pairs->AddBack(Collection.Tuple.Pair->New("a", IntRef->New(1))<String, IntRef>);
pairs->AddBack(Collection.Tuple.Pair->New("b", IntRef->New(2))<String, IntRef>);
hash := Collection.Hash->Dict(pairs)<String, IntRef>;
hash->Find("a")->PrintLine(); # 1

Empty #

Clears the map

method : public : Empty() ~ Nil

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("a", 1);
hash->Empty();
hash->IsEmpty()->PrintLine(); # true

Find # native

Searches for a value in a hash

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

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Vfound value, Nil if not found

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("price", 99);
hash->Find("price")->PrintLine(); # 99

GetCapacity #

Gets the hash table capacity

method : public : GetCapacity() ~ Hash->Capacity

Return

TypeDescription
Hash->Capacityhash table capacity

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->GetCapacity()->PrintLine();

GetKeyValues #

Gets a collection of key/value pairs

method : public : GetKeyValues() ~ Vector<Pair<K,V>>

Return

TypeDescription
Vector<Pair<K,V>>vector of key/value pairs

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("m", 100);
kvs := hash->GetKeyValues()<Collection.Pair<String, IntRef>>;
each(kv := kvs) {
   "{kv->GetFirst()}: {kv->GetSecond()}"->PrintLine();
};

GetKeys # native

Get a collection of keys

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

Return

TypeDescription
Vector<K>vector of keys

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("a", 1);
hash->Insert("b", 2);
keys := hash->GetKeys()<String>;
each(k := keys) {
   k->PrintLine();
};

GetValues # native

Gets a collection of values

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

Return

TypeDescription
Vector<V>vector of values

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("x", 10);
hash->Insert("y", 20);
vals := hash->GetValues()<IntRef>;
each(v := vals) {
   v->PrintLine();
};

Has #

Checks for a value in a hash

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

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Booltrue if found, false otherwise

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("k", 1);
hash->Has("k")->PrintLine();   # true
hash->Has("z")->PrintLine();   # false

Insert #

Inserts a value into the hash

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

Parameters

NameTypeDescription
keyKkey
valueVvalue

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("count", 42);
hash->Find("count")->PrintLine(); # 42

IsAutoResize #

Gets auto-resize setting

method : public : IsAutoResize() ~ Bool

Return

TypeDescription
Booltrue if auto-resize is set, false otherwise

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->IsAutoResize()->PrintLine(); # true

IsEmpty #

Checks to see if the hash table is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->IsEmpty()->PrintLine(); # true
hash->Insert("a", 1);
hash->IsEmpty()->PrintLine(); # false

New # constructor

Default constructor

New(auto_resize:Bool)

Parameters

NameTypeDescription
auto_resizeBoolif true, automatically resized the hash table

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("apples", 3);
hash->Insert("bananas", 5);
hash->Size()->PrintLine(); # 2

New # constructor

Default constructor

New(capacity:Hash->Capacity, auto_resize:Bool)

Parameters

NameTypeDescription
capacityHash->Capacitycapacity of hash table
auto_resizeBoolif true, automatically resized the hash table

Example

hash := Collection.Hash->New(Collection.Hash->Capacity->MEDIUM)<String, IntRef>;
hash->Insert("key", 42);
hash->Find("key")->PrintLine(); # 42

Remove # native

Removes a value from the hash

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

Parameters

NameTypeDescription
keyKkey for value to remove

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("del", 9);
hash->Remove("del")->PrintLine(); # true
hash->Has("del")->PrintLine();    # false

Resize # native

Resizes the hash table

method : public : native : Resize(capacity:Hash->Capacity, auto_resize:Bool) ~ Nil

Parameters

NameTypeDescription
capacityHash->Capacitytable capacity
auto_resizeBooltrue for hash table auto resizing, false otherwise

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("a", 1);
hash->Resize(Collection.Hash->Capacity->LARGE);
hash->Find("a")->PrintLine(); # 1

SetAutoResize #

Set auto-resize setting

method : public : SetAutoResize(auto_resize:Bool) ~ Nil

Parameters

NameTypeDescription
auto_resizeBooltrue if auto-resize is enable, false otherwise

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->SetAutoResize(false);
hash->IsAutoResize()->PrintLine(); # false

SetCapacity #

Sets hash table capacity

method : public : SetCapacity(capacity:Hash->Capacity) ~ Nil

Parameters

NameTypeDescription
capacityHash->Capacityhash table capacity

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->SetCapacity(Collection.Hash->Capacity->MEDIUM);
hash->GetCapacity()->PrintLine();

Size #

Size of map

method : public : Size() ~ Int

Return

TypeDescription
Intsize of map

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("a", 1);
hash->Insert("b", 2);
hash->Size()->PrintLine(); # 2

ToString #

Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.

method : public : ToString() ~ String

Return

TypeDescription
Stringstring representation

Example

hash := Collection.Hash->New()<String, IntRef>;
hash->Insert("x", 10);
hash->Insert("y", 20);
hash->ToString()->PrintLine();