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.

BitSet

Growable set of bits packed 64 to an Int

Example

bits := Collection.BitSet->New(128);
bits->Set(3); bits->Set(64); bits->Set(100);
bits->Get(64)->PrintLine();          # true
bits->Cardinality()->PrintLine();    # 3
bits->NextSetBit(4)->PrintLine();    # 64

Operations

And #

Keeps only the bits also set in another set (in place)

method : public : And(that:BitSet) ~ BitSet

Parameters

NameTypeDescription
thatBitSetother set (Nil clears every bit)

Return

TypeDescription
BitSetthis set

Example

a := Collection.BitSet->New(8); a->Set(1); a->Set(2);
b := Collection.BitSet->New(8); b->Set(2);
a->And(b)->Cardinality()->PrintLine(); # 1

AndNot #

Clears the bits set in another set (in place)

method : public : AndNot(that:BitSet) ~ BitSet

Parameters

NameTypeDescription
thatBitSetother set (Nil changes nothing)

Return

TypeDescription
BitSetthis set

Example

a := Collection.BitSet->New(8); a->Set(1); a->Set(2);
b := Collection.BitSet->New(8); b->Set(2);
a->AndNot(b)->Get(2)->PrintLine(); # false

Cardinality # native

Counts the set bits

method : public : native : Cardinality() ~ Int

Return

TypeDescription
Intnumber of set bits

Example

bits := Collection.BitSet->New(8);
bits->Set(1); bits->Set(2);
bits->Cardinality()->PrintLine(); # 2

Clear # native

Clears a bit

method : public : native : Clear(index:Int) ~ Nil

Parameters

NameTypeDescription
indexIntbit index (indexes past the size are already clear)

Example

bits := Collection.BitSet->New(8);
bits->Set(2);
bits->Clear(2);
bits->Get(2)->PrintLine(); # false

Copy #

Copies the set

method : public : Copy() ~ BitSet

Return

TypeDescription
BitSetnew set with the same bits

Example

a := Collection.BitSet->New(8); a->Set(1);
b := a->Copy();
b->Set(2);
a->Cardinality()->PrintLine(); # 1

Empty #

Clears every bit; the size is kept

method : public : Empty() ~ Nil

Example

bits := Collection.BitSet->New(8);
bits->Set(1);
bits->Empty();
bits->Cardinality()->PrintLine(); # 0

Get # native

Gets a bit

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

Parameters

NameTypeDescription
indexIntbit index

Return

TypeDescription
Booltrue if set, false if clear or out of range

Example

bits := Collection.BitSet->New(8);
bits->Set(5);
bits->Get(5)->PrintLine(); # true
bits->Get(6)->PrintLine(); # false

GetWords #

Gets the backing words; bit i is bit (i and 63) of word (i >> 6). The array is shared, not copied.

method : public : GetWords() ~ Int[]

Return

TypeDescription
Intwords

Example

bits := Collection.BitSet->New(8);
bits->Set(0);
bits->GetWords()[0]->PrintLine(); # 1

New # constructor

Default constructor

New()

Example

bits := Collection.BitSet->New();
bits->Set(10);
bits->Size()->PrintLine(); # 11

New # constructor

Constructor for a number of bits, all clear

New(size:Int)

Parameters

NameTypeDescription
sizeIntnumber of bits

Example

bits := Collection.BitSet->New(65);
bits->Size()->PrintLine(); # 65

NextSetBit # native

Finds the next set bit at or after an index

method : public : native : NextSetBit(start:Int) ~ Int

Parameters

NameTypeDescription
startIntindex to start at

Return

TypeDescription
Intindex of the next set bit, or -1 if there is none

Example

bits := Collection.BitSet->New(200);
bits->Set(70); bits->Set(130);
bits->NextSetBit(0)->PrintLine();   # 70
bits->NextSetBit(71)->PrintLine();  # 130
bits->NextSetBit(131)->PrintLine(); # -1

Or #

Adds the bits set in another set (in place)

method : public : Or(that:BitSet) ~ BitSet

Parameters

NameTypeDescription
thatBitSetother set (Nil changes nothing)

Return

TypeDescription
BitSetthis set

Example

a := Collection.BitSet->New(8); a->Set(1);
b := Collection.BitSet->New(8); b->Set(2);
a->Or(b)->Cardinality()->PrintLine(); # 2

Set # native

Sets a bit, growing the set when the index is past its size

method : public : native : Set(index:Int) ~ Nil

Parameters

NameTypeDescription
indexIntbit index (negative indexes are ignored)

Example

bits := Collection.BitSet->New();
bits->Set(200);
bits->Get(200)->PrintLine(); # true

Set #

Sets or clears a bit

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

Parameters

NameTypeDescription
indexIntbit index (negative indexes are ignored)
valueBooltrue to set, false to clear

Example

bits := Collection.BitSet->New(8);
bits->Set(2, true);
bits->Get(2)->PrintLine(); # true

Size #

Number of bits: the size given to the constructor, or one past the highest bit ever set if that is larger

method : public : Size() ~ Int

Return

TypeDescription
Intnumber of bits

Example

bits := Collection.BitSet->New(10);
bits->Size()->PrintLine(); # 10

ToString #

Formats the set into a string of the indexes of its set bits

method : public : ToString() ~ String

Return

TypeDescription
Stringstring representation

Example

bits := Collection.BitSet->New(8);
bits->Set(1); bits->Set(5);
bits->ToString()->PrintLine(); # {1,5}

Xor #

Flips the bits set in another set (in place)

method : public : Xor(that:BitSet) ~ BitSet

Parameters

NameTypeDescription
thatBitSetother set (Nil changes nothing)

Return

TypeDescription
BitSetthis set

Example

a := Collection.BitSet->New(8); a->Set(1); a->Set(2);
b := Collection.BitSet->New(8); b->Set(2); b->Set(3);
a->Xor(b)->Cardinality()->PrintLine(); # 2