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.

Cache

MRU/LRU object cache

Example

cache := Collection.Cache->New(Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(415, "San Francisco");
cache->Insert(925, "East Bay");
cache->Insert(650, "Mountain View");

cache->Find(650)->PrintLine();
cache->Find(650)->PrintLine();

cache->Find(415)->PrintLine();

cache->Find(925)->PrintLine();
cache->Find(925)->PrintLine();

cache->Insert(510, "Oakland");
cache->Find(510)->PrintLine();
cache->Find(510)->PrintLine();
cache->Find(510)->PrintLine();

"---"->PrintLine();
values := cache->GetKeys()<IntRef>;
each(value := values) {
   value->PrintLine();
};

Operations

Empty #

Clears the cache

method : public : Empty() ~ Nil

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(1, "a");
cache->Empty();
cache->IsEmpty()->PrintLine(); # true

Find #

Searches for a value in cache and updates access priority for LRU/MRU

method : public : Find(key:K) ~ S

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Sfound value, Nil if not found

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(1, "one");
cache->Find(1)->PrintLine();  # one
cache->Find(99)->PrintLine(); # (Nil — nothing printed)

GetKeyValues #

Gets a collection of key/value pairs

method : public : GetKeyValues() ~ Vector<Pair<K,S>>

Return

TypeDescription
Vector<Pair<K,S>>vector of key/value pairs

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 2)<IntRef, String>;
cache->Insert(10, "ten");
kvs := cache->GetKeyValues()<Collection.Pair<IntRef, String>>;
kvs->Size()->PrintLine(); # 1

GetKeys #

Get a collection of keys

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

Return

TypeDescription
Vector<K>vector of keys

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(1, "a");
cache->Insert(2, "b");
keys := cache->GetKeys()<IntRef>;
keys->Size()->PrintLine(); # 2

GetValues #

Gets a collection of values

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

Return

TypeDescription
Vector<S>vector of values

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(1, "alpha");
cache->Insert(2, "beta");
vals := cache->GetValues()<String>;
each(v := vals) {
   v->PrintLine();
};

Has #

Checks for a value in a cache

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

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Booltrue if found, false otherwise

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(7, "seven");
cache->Has(7)->PrintLine();  # true
cache->Has(99)->PrintLine(); # false

Insert #

Inserts a value into the cache. A new key in a full cache first evicts the least (LRU) or most (MRU) recently used entry; an existing key is updated and becomes the most recently used.

method : public : Insert(key:K, value:S) ~ Bool

Parameters

NameTypeDescription
keyKkey
valueSvalue

Return

TypeDescription
Booltrue if inserted, false if the key is Nil or the cache size is less than 1

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(1, "alpha");
cache->Insert(2, "beta");
cache->Size()->PrintLine(); # 2

IsEmpty #

Checks to see if the cache is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->IsEmpty()->PrintLine(); # true
cache->Insert(1, "a");
cache->IsEmpty()->PrintLine(); # false

New # constructor

Default constructor

New(type:Cache->Type, max:Int)

Parameters

NameTypeDescription
typeCache->TypeMRU or LRU cache
maxIntcache max size

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(1, "one");
cache->Insert(2, "two");
cache->Find(1)->PrintLine(); # one

Remove #

Removes a value from the cache

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

Parameters

NameTypeDescription
keyKkey for value to remove

Return

TypeDescription
Booltrue if removed, false otherwise

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(5, "five");
cache->Remove(5)->PrintLine(); # true
cache->Has(5)->PrintLine();    # false

Size #

Size of cache

method : public : Size() ~ Int

Return

TypeDescription
Intsize of cache

Example

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 3)<IntRef, String>;
cache->Insert(1, "a");
cache->Size()->PrintLine(); # 1

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

cache := Collection.Cache->New(Collection.Cache->Type->LRU, 2)<IntRef, String>;
cache->Insert(10, "ten");
cache->Insert(20, "twenty");
cache->ToString()->PrintLine();