v2026.6.4
All Bundles
Bundle Generic collections library: Vector (dynamic array), Map (hash map), Set, MultiMap, 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

Empty #

Clears the set

method : public : Empty() ~ Nil

Example

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

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

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

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

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