v2026.11.2
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.

IntMap

Hash table from Int keys to Int values: open addressing over plain arrays, so nothing is boxed. Every Int is a valid key, including 0 and the Int64 extremes.

Example

counts := Collection.IntMap->New();
counts->Add(7, 1); counts->Add(7, 1); counts->Add(3, 1);
counts->Find(7)->PrintLine();       # 2
counts->Find(9, -1)->PrintLine();   # -1
counts->Has(3)->PrintLine();        # true
counts->Size()->PrintLine();        # 2

Operations

Add # native

Adds to the value of a key; a missing key starts at 0

method : public : native : Add(key:Int, delta:Int) ~ Int

Parameters

NameTypeDescription
keyIntkey
deltaIntamount to add

Return

TypeDescription
Intnew value

Example

map := Collection.IntMap->New();
map->Add(1, 5);
map->Add(1, 2)->PrintLine(); # 7

Each #

Calls a function for each key and value. The function must not change the map.

method : public : Each(f:(Int,Int)~Nil) ~ IntMap

Parameters

NameTypeDescription
f(Int,Int)~Nilfunction called

Return

TypeDescription
IntMapthis map

Example

map := Collection.IntMap->New();
map->Insert(1, 10);
map->Each(\(k, v) => { "{$k}={$v}"->PrintLine(); });

Empty #

Removes every entry

method : public : Empty() ~ Nil

Example

map := Collection.IntMap->New();
map->Insert(1, 1);
map->Empty();
map->Size()->PrintLine(); # 0

Find #

Finds the value of a key

method : public : Find(key:Int) ~ Int

Parameters

NameTypeDescription
keyIntkey

Return

TypeDescription
Intvalue, or 0 if the key is missing (use Has or Find(key, missing) to tell)

Example

map := Collection.IntMap->New();
map->Insert(1, 10);
map->Find(1)->PrintLine(); # 10
map->Find(2)->PrintLine(); # 0

Find # native

Finds the value of a key

method : public : native : Find(key:Int, missing:Int) ~ Int

Parameters

NameTypeDescription
keyIntkey
missingIntvalue returned when the key is missing

Return

TypeDescription
Intvalue, or missing

Example

map := Collection.IntMap->New();
map->Find(2, -1)->PrintLine(); # -1

GetKeys # native

Gets the keys. GetKeys and GetValues list the entries in the same order.

method : public : native : GetKeys() ~ Int[]

Return

TypeDescription
Intarray of keys

Example

map := Collection.IntMap->New();
map->Insert(1, 10); map->Insert(2, 20);
map->GetKeys()->Size()->PrintLine(); # 2

GetValues # native

Gets the values, in the same order as GetKeys

method : public : native : GetValues() ~ Int[]

Return

TypeDescription
Intarray of values

Example

map := Collection.IntMap->New();
map->Insert(1, 10); map->Insert(2, 20);
map->GetValues()->Size()->PrintLine(); # 2

Has # native

Checks for a key

method : public : native : Has(key:Int) ~ Bool

Parameters

NameTypeDescription
keyIntkey

Return

TypeDescription
Booltrue if found, false otherwise

Example

map := Collection.IntMap->New();
map->Insert(0, 0);
map->Has(0)->PrintLine(); # true
map->Has(1)->PrintLine(); # false

Insert # native

Inserts a value, replacing the value of an existing key

method : public : native : Insert(key:Int, value:Int) ~ Nil

Parameters

NameTypeDescription
keyIntkey
valueIntvalue

Example

map := Collection.IntMap->New();
map->Insert(-5, 25);
map->Find(-5)->PrintLine(); # 25

IsEmpty #

Checks to see if the map is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

map := Collection.IntMap->New();
map->IsEmpty()->PrintLine(); # true

New # constructor

Default constructor

New()

Example

map := Collection.IntMap->New();
map->Insert(1, 100);
map->Size()->PrintLine(); # 1

New # constructor

Constructor that reserves room for a number of entries

New(capacity:Int)

Parameters

NameTypeDescription
capacityIntnumber of entries expected

Example

map := Collection.IntMap->New(100000);
map->Size()->PrintLine(); # 0

Remove # native

Removes a key

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

Parameters

NameTypeDescription
keyIntkey

Return

TypeDescription
Booltrue if removed, false if the key was missing

Example

map := Collection.IntMap->New();
map->Insert(4, 16);
map->Remove(4)->PrintLine(); # true
map->Has(4)->PrintLine();    # false

Size #

Number of entries

method : public : Size() ~ Int

Return

TypeDescription
Intnumber of entries

Example

map := Collection.IntMap->New();
map->Insert(1, 1);
map->Size()->PrintLine(); # 1

ToString #

Formats the map into a string

method : public : ToString() ~ String

Return

TypeDescription
Stringstring representation

Example

map := Collection.IntMap->New();
map->Insert(1, 10);
map->ToString()->PrintLine(); # [(1:10)]