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.

IntVector

Growable array of Int values; nothing is boxed

Example

v := Collection.IntVector->New();
v->AddBack(3); v->AddBack(1); v->AddBack(2);
v->Sort();
v->Get(0)->PrintLine();   # 1
v->Sum()->PrintLine();    # 6
v->Size()->PrintLine();   # 3

Operations

AddBack # native

Adds a value to the end

method : public : native : AddBack(value:Int) ~ Nil

Parameters

NameTypeDescription
valueIntvalue

Example

v := Collection.IntVector->New();
v->AddBack(42);
v->Get(0)->PrintLine(); # 42

Clear #

Removes every value; the reserved room is kept

method : public : Clear() ~ Nil

Example

v := Collection.IntVector->New([1, 2]);
v->Clear();
v->Size()->PrintLine(); # 0

Each #

Calls a function for each value

method : public : Each(f:(Int)~Nil) ~ IntVector

Parameters

NameTypeDescription
f(Int)~Nilfunction called

Return

TypeDescription
IntVectorthis vector

Example

v := Collection.IntVector->New([4, 5]);
v->Each(\(i) => { i->PrintLine(); });

Empty #

Removes every value; the same as Clear

method : public : Empty() ~ Nil

Example

v := Collection.IntVector->New([1, 2]);
v->Empty();
v->IsEmpty()->PrintLine(); # true

Find # native

Finds the first index of a value

method : public : native : Find(value:Int) ~ Int

Parameters

NameTypeDescription
valueIntvalue to find

Return

TypeDescription
Intindex, or -1 if not found

Example

v := Collection.IntVector->New([4, 5, 6]);
v->Find(6)->PrintLine(); # 2

First #

Gets the first value

method : public : First() ~ Int

Return

TypeDescription
Intfirst value, or 0 if empty

Example

v := Collection.IntVector->New([4, 5]);
v->First()->PrintLine(); # 4

Get # native

Gets an indexed value

method : public : native : Get(index:Int) ~ Int

Parameters

NameTypeDescription
indexIntindex

Return

TypeDescription
Intvalue, or 0 if the index is out of range

Example

v := Collection.IntVector->New([4, 5]);
v->Get(1)->PrintLine(); # 5

Has #

Checks for a value

method : public : Has(value:Int) ~ Bool

Parameters

NameTypeDescription
valueIntvalue to find

Return

TypeDescription
Booltrue if found, false otherwise

Example

v := Collection.IntVector->New([4, 5, 6]);
v->Has(5)->PrintLine(); # true

IsEmpty #

Checks to see if the vector is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

v := Collection.IntVector->New();
v->IsEmpty()->PrintLine(); # true

Last #

Gets the last value

method : public : Last() ~ Int

Return

TypeDescription
Intlast value, or 0 if empty

Example

v := Collection.IntVector->New([4, 5]);
v->Last()->PrintLine(); # 5

New # constructor

Default constructor

New()

Example

v := Collection.IntVector->New();
v->AddBack(7);
v->Size()->PrintLine(); # 1

New # constructor

Constructor that reserves room for a number of values

New(capacity:Int)

Parameters

NameTypeDescription
capacityIntnumber of values to reserve

Example

v := Collection.IntVector->New(1000);
v->Size()->PrintLine(); # 0

New # constructor

Copy constructor

New(values:Int[])

Parameters

NameTypeDescription
valuesIntvalues to copy

Example

v := Collection.IntVector->New([5, 6, 7]);
v->Get(2)->PrintLine(); # 7

Remove #

Removes an indexed value, shifting the later values down

method : public : Remove(index:Int) ~ Int

Parameters

NameTypeDescription
indexIntindex

Return

TypeDescription
Intremoved value, or 0 if the index is out of range

Example

v := Collection.IntVector->New([4, 5, 6]);
v->Remove(1)->PrintLine(); # 5
v->Get(1)->PrintLine();    # 6

RemoveBack #

Removes the last value

method : public : RemoveBack() ~ Int

Return

TypeDescription
Intremoved value, or 0 if empty

Example

v := Collection.IntVector->New([4, 5]);
v->RemoveBack()->PrintLine(); # 5
v->Size()->PrintLine();       # 1

Reserve #

Reserves room for at least a number of values

method : public : Reserve(capacity:Int) ~ Nil

Parameters

NameTypeDescription
capacityIntnumber of values

Example

v := Collection.IntVector->New();
v->Reserve(1000000);
v->Size()->PrintLine(); # 0

Set # native

Sets an indexed value

method : public : native : Set(value:Int, index:Int) ~ Bool

Parameters

NameTypeDescription
valueIntvalue
indexIntindex

Return

TypeDescription
Booltrue if set, false if the index is out of range

Example

v := Collection.IntVector->New([4, 5]);
v->Set(9, 0)->PrintLine(); # true
v->Get(0)->PrintLine();    # 9

Size #

Size of vector

method : public : Size() ~ Int

Return

TypeDescription
Intnumber of values

Example

v := Collection.IntVector->New([1, 2]);
v->Size()->PrintLine(); # 2

Sort #

Sorts the values in ascending order (a stable merge sort, O(n log n))

method : public : Sort() ~ Nil

Example

v := Collection.IntVector->New([3, -1, 2]);
v->Sort();
v->ToString()->PrintLine(); # [-1,2,3]

Sum # native

Sums the values

method : public : native : Sum() ~ Int

Return

TypeDescription
Intsum

Example

v := Collection.IntVector->New([4, 5, 6]);
v->Sum()->PrintLine(); # 15

ToArray #

Copies the values into an array

method : public : ToArray() ~ Int[]

Return

TypeDescription
Intarray of values

Example

v := Collection.IntVector->New([1, 2]);
v->ToArray()->Size()->PrintLine(); # 2

ToString #

Formats the vector into a string

method : public : ToString() ~ String

Return

TypeDescription
Stringstring representation

Example

v := Collection.IntVector->New([1, 2]);
v->ToString()->PrintLine(); # [1,2]