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.

Trie

Trie (prefix tree) holding a set of strings. Add, Has, HasPrefix and Remove cost O(length of the string) times the log of the branching at each node; WithPrefix lists matches in sorted order. Characters are compared as the string's own character values.

Operations

Add #

Adds a string

method : public : Add(word:String) ~ Bool

Parameters

NameTypeDescription
wordStringstring to add

Return

TypeDescription
Booltrue if added, false if it was already present or is Nil

Example

t := Collection.Trie->New();
t->Add("car")->PrintLine(); # true
t->Add("car")->PrintLine(); # false

Empty #

Removes every string

method : public : Empty() ~ Nil

Has #

Checks whether a whole string was added

method : public : Has(word:String) ~ Bool

Parameters

NameTypeDescription
wordStringstring to look for

Return

TypeDescription
Booltrue if present

Example

t := Collection.Trie->New();
t->Add("car");
t->Has("car")->PrintLine(); # true
t->Has("ca")->PrintLine();  # false

HasPrefix #

Checks whether any added string starts with a prefix

method : public : HasPrefix(prefix:String) ~ Bool

Parameters

NameTypeDescription
prefixStringprefix to look for (an empty prefix matches if the trie is not empty)

Return

TypeDescription
Booltrue if some string starts with it

Example

t := Collection.Trie->New();
t->Add("car");
t->HasPrefix("ca")->PrintLine(); # true

IsEmpty #

Checks for no strings

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty

New # constructor

Default constructor

New()

Example

t := Collection.Trie->New();
t->Add("car"); t->Add("cat");
t->Size()->PrintLine(); # 2

Remove #

Removes a string, freeing the nodes only it used

method : public : Remove(word:String) ~ Bool

Parameters

NameTypeDescription
wordStringstring to remove

Return

TypeDescription
Booltrue if it was present

Example

t := Collection.Trie->New();
t->Add("car"); t->Add("cart");
t->Remove("cart")->PrintLine(); # true
t->Has("car")->PrintLine();     # true

Size #

Gets the number of strings

method : public : Size() ~ Int

Return

TypeDescription
Intsize

WithPrefix #

Lists the added strings that start with a prefix

method : public : WithPrefix(prefix:String) ~ Vector<String>

Parameters

NameTypeDescription
prefixStringprefix to match (an empty prefix lists everything)

Return

TypeDescription
Vector<String>matching strings in sorted order, empty if none

Example

t := Collection.Trie->New();
t->Add("cat"); t->Add("car"); t->Add("dog");
t->WithPrefix("ca")->Get(0)->PrintLine(); # car