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.

SetHash

Unordered set of generic objects

Example

# insert elements
set_hash := Collection.SetHash->New()<String>;
set_hash->Insert("San Francisco");
set_hash->Insert("Oakland");
set_hash->Insert("East Bay");

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

# get value by key
set_hash->Has("Oakland")->PrintLine();

Operations

Add #

Adds a key to the set; the same as Insert, but says whether it was new

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

Parameters

NameTypeDescription
keyKkey

Return

TypeDescription
Booltrue if added, false if it was already in the set (or is Nil)

Example

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

Difference #

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

method : public : Difference(that:SetHash<K>) ~ SetHash<K>

Parameters

NameTypeDescription
thatSetHash<K>other set (Nil counts as empty)

Return

TypeDescription
SetHash<K>new set

Example

a := Collection.SetHash->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.SetHash->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:(K)~Nil) ~ SetHash<K>

Parameters

NameTypeDescription
f(K)~Nilfunction called

Return

TypeDescription
SetHash<K>this set

Example

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

Empty #

Clears the set

method : public : Empty() ~ Nil

Example

sh := Collection.SetHash->New()<String>;
sh->Insert("item");
sh->Empty();
sh->IsEmpty()->PrintLine(); # true

Filter #

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

method : public : Filter(f:(K)~Bool) ~ SetHash<K>

Parameters

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

Return

TypeDescription
SetHash<K>new set

Example

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

GetKeys #

Get a collection of keys

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

Return

TypeDescription
Vector<K>vector of keys

Example

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

Has #

Checks for key in set

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

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Booltrue if found, false otherwise

Example

sh := Collection.SetHash->New()<String>;
sh->Insert("present");
sh->Has("present")->PrintLine();  # true
sh->Has("absent")->PrintLine();   # false

Insert #

Inserts a key into the set

method : public : Insert(key:K) ~ Nil

Parameters

NameTypeDescription
keyKkey

Example

sh := Collection.SetHash->New()<String>;
sh->Insert("blue");
sh->Has("blue")->PrintLine(); # true

Intersect #

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

method : public : Intersect(that:SetHash<K>) ~ SetHash<K>

Parameters

NameTypeDescription
thatSetHash<K>other set (Nil counts as empty)

Return

TypeDescription
SetHash<K>new set

Example

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

IsEmpty #

Checks to see if the set is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

sh := Collection.SetHash->New()<String>;
sh->IsEmpty()->PrintLine(); # true
sh->Insert("z");
sh->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:SetHash<K>) ~ Bool

Parameters

NameTypeDescription
thatSetHash<K>other set (Nil counts as empty)

Return

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

Example

a := Collection.SetHash->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.SetHash->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:SetHash<K>) ~ Bool

Parameters

NameTypeDescription
thatSetHash<K>other set (Nil counts as empty)

Return

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

Example

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

New # constructor

Default constructor

New()

Example

sh := Collection.SetHash->New()<String>;
sh->Insert("hello");
sh->Size()->PrintLine(); # 1

Remove #

Removes a key from the set

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

Parameters

NameTypeDescription
keyKkey for value to remove

Return

TypeDescription
Booltrue if removed, false otherwise

Example

sh := Collection.SetHash->New()<String>;
sh->Insert("tmp");
sh->Remove("tmp")->PrintLine(); # true
sh->Has("tmp")->PrintLine();    # false

Size #

Size of set

method : public : Size() ~ Int

Return

TypeDescription
Intnumber of elements

Example

sh := Collection.SetHash->New()<String>;
sh->Insert("a"); sh->Insert("b");
sh->Size()->PrintLine(); # 2

SymmetricDifference #

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

method : public : SymmetricDifference(that:SetHash<K>) ~ SetHash<K>

Parameters

NameTypeDescription
thatSetHash<K>other set (Nil counts as empty)

Return

TypeDescription
SetHash<K>new set

Example

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

ToArray #

Gets all elements as an array

method : public : ToArray() ~ K[]

Return

TypeDescription
K[]array of elements

Example

set := Collection.SetHash->New()<String>;
set->Insert("p"); set->Insert("q");
set->ToArray()->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

sh := Collection.SetHash->New()<String>;
sh->Insert("m"); sh->Insert("n");
sh->ToString()->PrintLine();

ToVector #

Gets all elements as a vector; the same as GetKeys

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

Return

TypeDescription
Vector<K>vector of elements

Example

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

Union #

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

method : public : Union(that:SetHash<K>) ~ SetHash<K>

Parameters

NameTypeDescription
thatSetHash<K>other set (Nil counts as empty)

Return

TypeDescription
SetHash<K>new set

Example

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