collections

A set of data structures: stack, queue, set, ordered map, min-heap, trie, ring buffer, and singly-linked list, plus helpers for native arrays and tuples. Import it with import collections.

Most structures are handle-based: new() returns an integer id that you pass to every other call, and free(id) releases it. The exceptions are collections.array and collections.tuple, which operate directly on Langoost native arrays (no handle, no free).

collections.stack

FunctionSignatureDescription
newcollections.stack.new() → intCreate a stack, return its id
pushcollections.stack.push(id: int, value: any) → boolPush a value (false if id unknown)
popcollections.stack.pop(id: int) → anyPop the top value (void if empty)
peekcollections.stack.peek(id: int) → anyView the top value (void if empty)
sizecollections.stack.size(id: int) → intNumber of elements
isEmptycollections.stack.isEmpty(id: int) → boolWhether the stack is empty
freecollections.stack.free(id: int) → voidRelease the stack

collections.queue

FunctionSignatureDescription
newcollections.queue.new() → intCreate a queue, return its id
enqueuecollections.queue.enqueue(id: int, value: any) → boolAdd to the back (false if id unknown)
dequeuecollections.queue.dequeue(id: int) → anyRemove from the front (void if empty)
peekcollections.queue.peek(id: int) → anyView the front value (void if empty)
sizecollections.queue.size(id: int) → intNumber of elements
isEmptycollections.queue.isEmpty(id: int) → boolWhether the queue is empty
freecollections.queue.free(id: int) → voidRelease the queue

collections.set

A set of unique strings.

FunctionSignatureDescription
newcollections.set.new() → intCreate a set, return its id
addcollections.set.add(id: int, value: string) → boolAdd a value (false if id unknown)
hascollections.set.has(id: int, value: string) → boolWhether the value is present
removecollections.set.remove(id: int, value: string) → voidRemove a value
sizecollections.set.size(id: int) → intNumber of elements
toArraycollections.set.toArray(id: int) → string[]Members as an array (unordered)
freecollections.set.free(id: int) → voidRelease the set

collections.map

An ordered map with string keys; keys preserves insertion order.

FunctionSignatureDescription
newcollections.map.new() → intCreate a map, return its id
setcollections.map.set(id: int, key: string, value: any) → boolSet a key (false if id unknown)
getcollections.map.get(id: int, key: string) → anyGet a value (void if missing)
hascollections.map.has(id: int, key: string) → boolWhether the key exists
deletecollections.map.delete(id: int, key: string) → boolRemove a key
keyscollections.map.keys(id: int) → string[]Keys in insertion order
sizecollections.map.size(id: int) → intNumber of entries
freecollections.map.free(id: int) → voidRelease the map

collections.heap

A min-heap of integers.

FunctionSignatureDescription
newcollections.heap.new() → intCreate a heap, return its id
pushcollections.heap.push(id: int, value: int) → boolInsert a value (false if id unknown)
popcollections.heap.pop(id: int) → intRemove and return the minimum (0 if empty)
peekcollections.heap.peek(id: int) → intView the minimum (void if empty)
sizecollections.heap.size(id: int) → intNumber of elements
freecollections.heap.free(id: int) → voidRelease the heap

collections.trie

A prefix tree over strings.

FunctionSignatureDescription
newcollections.trie.new() → intCreate a trie, return its id
insertcollections.trie.insert(id: int, word: string) → boolInsert a word (false if id unknown)
searchcollections.trie.search(id: int, word: string) → boolWhether the exact word is present
startsWithcollections.trie.startsWith(id: int, prefix: string) → boolWhether any word has the prefix
wordscollections.trie.words(id: int) → string[]All stored words
freecollections.trie.free(id: int) → voidRelease the trie

collections.ring

A fixed-capacity ring buffer.

FunctionSignatureDescription
newcollections.ring.new(capacity: int) → intCreate a ring buffer (capacity must be > 0)
pushcollections.ring.push(id: int, value: any) → boolAdd a value (false if full or id unknown)
popcollections.ring.pop(id: int) → anyRemove the oldest value (void if empty)
sizecollections.ring.size(id: int) → intNumber of elements
isFullcollections.ring.isFull(id: int) → boolWhether the buffer is at capacity
freecollections.ring.free(id: int) → voidRelease the ring buffer

collections.list

A handle-based ordered list of strings.

FunctionSignatureDescription
newcollections.list.new() → intCreate a list, return its id
appendcollections.list.append(id: int, value: any) → voidAppend to the end (stored as a string)
prependcollections.list.prepend(id: int, value: any) → voidPrepend to the front (stored as a string)
getcollections.list.get(id: int, index: int) → stringValue at index (empty string if out of range)
sizecollections.list.size(id: int) → intNumber of elements
toArraycollections.list.toArray(id: int) → string[]All elements as an array
freecollections.list.free(id: int) → voidRelease the list

collections.array

Operates on Langoost native arrays (no handle). Mutating helpers return a new array.

FunctionSignatureDescription
newcollections.array.new() → arrayCreate an empty array
lengthcollections.array.length(arr: array) → intElement count
pushcollections.array.push(arr: array, value: any) → arrayNew array with value appended
popcollections.array.pop(arr: array) → anyLast element (does not mutate)
firstcollections.array.first(arr: array) → anyFirst element
lastcollections.array.last(arr: array) → anyLast element
containscollections.array.contains(arr: array, value: any) → boolWhether value is present
indexOfcollections.array.indexOf(arr: array, value: any) → intIndex of value, or -1
reversecollections.array.reverse(arr: array) → arrayNew reversed array
uniquecollections.array.unique(arr: array) → arrayNew array with duplicates removed
slicecollections.array.slice(arr: array, start: int, end: int) → arraySub-array [start, end)
joincollections.array.join(arr: array, sep: string) → stringJoin elements with a separator

collections.tuple

An immutable fixed-size view over a native array (no handle).

FunctionSignatureDescription
newcollections.tuple.new(vals: array) → arrayCreate a tuple from an array (copies it)
getcollections.tuple.get(tuple: array, index: int) → anyElement at index (empty string if out of range)
sizecollections.tuple.size(tuple: array) → intElement count
containscollections.tuple.contains(tuple: array, value: any) → boolWhether value is present
toArraycollections.tuple.toArray(tuple: array) → arrayReturn the underlying array

Example

import collections

// handle-based: ordered map
let m = collections.map.new()
collections.map.set(m, "name", "ada")
collections.map.set(m, "role", "engineer")
print(collections.map.get(m, "name"))   // ada
print(collections.map.keys(m))           // ["name", "role"]
collections.map.free(m)

// native arrays need no handle
let nums = [3, 1, 2, 1]
print(collections.array.unique(nums))    // [3, 1, 2]
print(collections.array.join(nums, "-")) // 3-1-2-1
Standard library · View as Markdown · llms-full.txt