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.

HashSet

Hash-based set for O(1) membership testing without storing values

Example

set := Collection.HashSet->New()<IntRef>;
set->Add(IntRef->New(1));
set->Add(IntRef->New(2));
set->Add(IntRef->New(3));

set->Has(IntRef->New(2))->PrintLine(); # true
set->Has(IntRef->New(5))->PrintLine(); # false

set->Remove(IntRef->New(2));
set->Has(IntRef->New(2))->PrintLine(); # false

Operations

Add #

Adds a value to the set

method : public : Add(value:H) ~ Bool

Parameters

NameTypeDescription
valueHvalue to add

Return

TypeDescription
Booltrue if added, false if already exists

Example

set := Collection.HashSet->New()<String>;
set->Add("apple")->PrintLine();  # true
set->Add("apple")->PrintLine();  # false (duplicate)
set->Size()->PrintLine();        # 1

Difference #

Elements in this set that are not in the other set. Neither set is changed.

method : public : Difference(that:HashSet<H>) ~ HashSet<H>

Parameters

NameTypeDescription
thatHashSet<H>other set (Nil counts as empty)

Return

TypeDescription
HashSet<H>new set

Example

a := Collection.HashSet->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.HashSet->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Difference(b)->Has(1)->PrintLine(); # true

Each #

Calls a function for each element

method : public : Each(f:(H)~Nil) ~ HashSet<H>

Parameters

NameTypeDescription
f(H)~Nilfunction called

Return

TypeDescription
HashSet<H>this set

Example

set := Collection.HashSet->New()<String>;
set->Insert("x"); set->Insert("y");
set->Each(\(s) => { s->PrintLine(); });

Empty #

Clears the set

method : public : Empty() ~ Nil

Example

set := Collection.HashSet->New()<String>;
set->Add("a");
set->Empty();
set->IsEmpty()->PrintLine(); # true

Filter #

Keeps the elements a function accepts. The set is not changed.

method : public : Filter(f:(H)~Bool) ~ HashSet<H>

Parameters

NameTypeDescription
f(H)~Boolfunction that returns true for each element to keep

Return

TypeDescription
HashSet<H>new set

Example

set := Collection.HashSet->New()<String>;
set->Insert("apple"); set->Insert("kiwi");
set->Filter(\(s) => s->Size() > 4)->Size()->PrintLine(); # 1

GetKeys #

Gets all values as a vector; the same as ToVector, for the method name Set and SetHash use

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

Return

TypeDescription
Vector<H>vector of values

Example

set := Collection.HashSet->New()<String>;
set->Insert("x"); set->Insert("y");
set->GetKeys()->Size()->PrintLine(); # 2

Has #

Checks if a value exists in the set

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

Parameters

NameTypeDescription
valueHvalue to check

Return

TypeDescription
Booltrue if found, false otherwise

Example

set := Collection.HashSet->New()<String>;
set->Add("hello");
set->Has("hello")->PrintLine(); # true
set->Has("world")->PrintLine(); # false

Insert #

Inserts a value into the set; the same as Add, for the method name Set and SetHash use

method : public : Insert(value:H) ~ Nil

Parameters

NameTypeDescription
valueHvalue to insert

Example

set := Collection.HashSet->New()<String>;
set->Insert("apple");
set->Has("apple")->PrintLine(); # true

Intersect #

Elements in both this set and the other set. Neither set is changed.

method : public : Intersect(that:HashSet<H>) ~ HashSet<H>

Parameters

NameTypeDescription
thatHashSet<H>other set (Nil counts as empty)

Return

TypeDescription
HashSet<H>new set

Example

a := Collection.HashSet->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.HashSet->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Intersect(b)->Size()->PrintLine(); # 2

IsEmpty #

Checks if set is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

set := Collection.HashSet->New()<String>;
set->IsEmpty()->PrintLine(); # true
set->Add("x");
set->IsEmpty()->PrintLine(); # false

IsSubset #

Checks that every element of this set is in the other set. The empty set is a subset of every set.

method : public : IsSubset(that:HashSet<H>) ~ Bool

Parameters

NameTypeDescription
thatHashSet<H>other set (Nil counts as empty)

Return

TypeDescription
Booltrue if this set is a subset of the other, false otherwise

Example

a := Collection.HashSet->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.HashSet->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Intersect(b)->IsSubset(b)->PrintLine(); # true
a->IsSubset(b)->PrintLine(); # false

IsSuperset #

Checks that every element of the other set is in this set

method : public : IsSuperset(that:HashSet<H>) ~ Bool

Parameters

NameTypeDescription
thatHashSet<H>other set (Nil counts as empty)

Return

TypeDescription
Booltrue if this set is a superset of the other, false otherwise

Example

a := Collection.HashSet->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.HashSet->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Union(b)->IsSuperset(a)->PrintLine(); # true

New # constructor

Default constructor

New()

Example

set := Collection.HashSet->New()<String>;
set->Add("apple");
set->Add("banana");
set->Size()->PrintLine(); # 2

Remove #

Removes a value from the set

method : public : Remove(value:H) ~ Bool

Parameters

NameTypeDescription
valueHvalue to remove

Return

TypeDescription
Booltrue if removed, false if not found

Example

set := Collection.HashSet->New()<String>;
set->Add("hello");
set->Remove("hello")->PrintLine(); # true
set->Has("hello")->PrintLine();    # false

Size #

Size of set

method : public : Size() ~ Int

Return

TypeDescription
Intnumber of elements

Example

set := Collection.HashSet->New()<String>;
set->Add("a");
set->Add("b");
set->Size()->PrintLine(); # 2

SymmetricDifference #

Elements in exactly one of the two sets. Neither set is changed.

method : public : SymmetricDifference(that:HashSet<H>) ~ HashSet<H>

Parameters

NameTypeDescription
thatHashSet<H>other set (Nil counts as empty)

Return

TypeDescription
HashSet<H>new set

Example

a := Collection.HashSet->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.HashSet->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->SymmetricDifference(b)->Size()->PrintLine(); # 2 (1 and 4)

ToArray #

Gets all values as an array

method : public : ToArray() ~ H[]

Return

TypeDescription
H[]array of values

Example

set := Collection.HashSet->New()<String>;
set->Add("p");
set->Add("q");
arr := set->ToArray();
arr->Size()->PrintLine(); # 2

ToString #

Formats the set into a string

method : public : ToString() ~ String

Return

TypeDescription
Stringstring representation

Example

set := Collection.HashSet->New()<String>;
set->Add("a");
set->Add("b");
set->ToString()->PrintLine();

ToVector #

Gets all values as a vector

method : public : ToVector() ~ Vector<H>

Return

TypeDescription
Vector<H>vector of values

Example

set := Collection.HashSet->New()<String>;
set->Add("x");
set->Add("y");
v := set->ToVector()<String>;
v->Size()->PrintLine(); # 2

Union #

Elements in this set, the other set, or both. Neither set is changed.

method : public : Union(that:HashSet<H>) ~ HashSet<H>

Parameters

NameTypeDescription
thatHashSet<H>other set (Nil counts as empty)

Return

TypeDescription
HashSet<H>new set

Example

a := Collection.HashSet->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.HashSet->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Union(b)->Size()->PrintLine(); # 4