v2026.5.3
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.

MultiMap

Ordered binary tree that holds multiple values with the same key

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("fruits", 1);
mmap->Insert("fruits", 2);
mmap->Insert("vegetables", 3);
values := mmap->Find("fruits")<IntRef>;
each(v := values) {
   v->PrintLine();
};

Operations

Each #

Function called for each element

method : public : Each(f:(K,V)~Nil) ~ MultiMap<K,V>

Parameters

NameTypeDescription
f(K,V)~Nilfunction called

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(1)); mmap->Insert("a", IntRef->New(2));
mmap->Each(\(k : String, v : IntRef) ~ Nil { "{$k}={$v}"->PrintLine(); });

Empty #

Clears the map

method : public : Empty() ~ Nil

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(1));
mmap->Empty();
mmap->IsEmpty()->PrintLine(); # true

Filter #

Uses the given function to filter out values

method : public : Filter(f:(K)~Bool) ~ MultiMap<K,V>

Parameters

NameTypeDescription
f(K)~Boolfunction to use a filter. If the function evaluates to true the value is added to the collection.

Return

TypeDescription
MultiMap<K,V>filtered MultiMap

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(1)); mmap->Insert("b", IntRef->New(2));
filtered := mmap->Filter(\(k : String) ~ Bool { return k->Equals("a"); })<String, IntRef>;
filtered->Size()->PrintLine(); # 1

Find #

Finds all values for a key in the map

method : public : Find(key:K) ~ Vector<V>

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Vector<V>vector of values, or Nil if not found

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("k", IntRef->New(10)); mmap->Insert("k", IntRef->New(20));
vals := mmap->Find("k")<IntRef>;
each(v := vals) { v->PrintLine(); } # 10, 20

GetKeys #

Get a collection of keys

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

Return

TypeDescription
Vector<K>vector of keys

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(1)); mmap->Insert("b", IntRef->New(2));
keys := mmap->GetKeys()<String>;
each(k := keys) { k->PrintLine(); }

GetValues #

Gets a collection of all values across all keys

method : public : GetValues() ~ Vector<V>

Return

TypeDescription
Vector<V>vector of values

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(1)); mmap->Insert("b", IntRef->New(2));
all_values := mmap->GetValues()<IntRef>;
all_values->Size()->PrintLine(); # 2

Has #

Checks for a value in a map

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

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Booltrue if found, false otherwise

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("x", IntRef->New(5));
mmap->Has("x")->PrintLine(); # true
mmap->Has("y")->PrintLine(); # false

Insert #

Inserts a value into the map

method : public : Insert(key:K, value:V) ~ Nil

Parameters

NameTypeDescription
keyKkey
valueVvalue

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("fruits", IntRef->New(1));
mmap->Insert("fruits", IntRef->New(2));
mmap->Find("fruits")->Size()->PrintLine(); # 2

IsEmpty #

Checks to see if the map is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->IsEmpty()->PrintLine(); # true
mmap->Insert("a", IntRef->New(1));
mmap->IsEmpty()->PrintLine(); # false

New # constructor

Default constructor

New()

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(1));
mmap->Size()->PrintLine(); # 1

Reduce #

Uses the given function to reduce the values

method : public : Reduce(a:K, f:(K,K)~K) ~ K

Parameters

NameTypeDescription
aKinitial value (i.e. accumulator)
f(K,K)~Kfunction to use a reduce

Return

TypeDescription
Kreduced value

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(0)); mmap->Insert("b", IntRef->New(0));
concat := mmap->Reduce("", \(acc : String, k : String) ~ String { return "{$acc}{$k}"; });
concat->PrintLine(); # ab

Remove #

Removes a set of values from the map

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

Parameters

NameTypeDescription
keyKkey for values to remove

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("del", IntRef->New(1)); mmap->Insert("del", IntRef->New(2));
mmap->Remove("del")->PrintLine(); # true
mmap->Has("del")->PrintLine();    # false

Size #

Size of unique keys

method : public : Size() ~ Int

Return

TypeDescription
Intsize of unique keys

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(1)); mmap->Insert("b", IntRef->New(2));
mmap->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

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(1)); mmap->Insert("a", IntRef->New(2));
mmap->ToString()->PrintLine(); # [(a:12)]

TotalSize #

Size of values

method : public : TotalSize() ~ Int

Return

TypeDescription
Intsize of values

Example

mmap := Collection.MultiMap->New()<String, IntRef>;
mmap->Insert("a", IntRef->New(1)); mmap->Insert("a", IntRef->New(2)); mmap->Insert("b", IntRef->New(3));
mmap->TotalSize()->PrintLine(); # 3