CollectionsThe built-in dynamic array type. All Seen programs have access to Array<T>.

Collections

Array<T>

The built-in dynamic array type. All Seen programs have access to Array<T>.

Construction

let arr = Array<Int>()                // empty
let arr = [1, 2, 3, 4, 5]            // literal
let arr = Array<Int>.withLength(100)  // pre-sized

Methods

MethodReturnDescription
push(value: T)VoidAppend element
pop()TRemove and return last element
get(index: Int)TGet element at index
set(index: Int, value: T)VoidSet element at index
length()IntNumber of elements

Runtime Array Functions

FunctionDescription
seen_arr_new_str()Create empty string array
seen_arr_new_ptr()Create empty pointer array
seen_arr_push_str(arr, s)Push string
seen_arr_push_i64(arr, val)Push integer
seen_arr_push_f64(arr, val)Push float
seen_arr_push_ptr(arr, ptr)Push pointer
seen_arr_get_str(arr, idx)Get string at index
seen_arr_get_i64(arr, idx)Get integer at index
seen_arr_set_i64(arr, idx, val)Set integer at index
seen_arr_set_str(arr, idx, s)Set string at index
seen_arr_length(arr)Get array length

Example

var names = Array<String>()
names.push("Alice")
names.push("Bob")
names.push("Charlie")

for name in names {
    println("Hello, {name}!")
}

Vec<T>

Contiguous vector with amortized O(1) push/pop and O(1) indexed access. Vec<T> is the preferred performance-oriented growable sequence when callers need repeated get, set, iteration, or conversion back to Array<T>.

import collections.vec

Construction

let v = Vec<Int>.new()
let v = Vec<Int>.withCapacity(1000)

Methods

MethodReturnDescription
push(value: T)VoidAppend element
pop()TRemove last
get(index: Int)TGet by index
set(index: Int, value: T)VoidSet by index
len()IntLength
isEmpty()BoolCheck empty
capacity()IntTotal capacity
clear()VoidRemove all elements
reverse()VoidReverse in place

HashMap<K, V>

Robin-hood hashing hash map. Iteration order is non-deterministic.

Generic keys in the source fallback hash through their stable string form, so supported primitive and string keys no longer collapse into a single bucket. For string-heavy workloads, StringHashMap<V> still avoids generic conversion overhead and uses byte-wise hashing directly.

import collections.hash_map

Construction

let map = HashMap<String, Int>()
let map = HashMap<String, Int>.withCapacity(100)

Methods

MethodReturnDescription
insert(key: K, value: V)VoidInsert or update
get(key: K)Option<V>Lookup by key
getOrDefault(key: K, defaultValue: V)VLookup without allocating an Option result
containsKey(key: K)BoolProbe without allocating an Option result
getUnchecked(key: K)VDirect lookup for hot paths after containsKey; missing keys are caller error
remove(key: K)Option<V>Remove by key
len()IntNumber of entries
isEmpty()BoolCheck empty
clear()VoidRemove all entries

Runtime HashMap Functions

4 variants per operation (key types: int_int, int_str, str_int, str_str):

FunctionDescription
hashmap_new_*()Create new map
hashmap_new_*_with_capacity(cap)Create with capacity
hashmap_insert_*(map, key, val)Insert
hashmap_get_*(map, key)Lookup
hashmap_getUnchecked_*(map, key)Direct lookup without constructing an Option wrapper
hashmap_remove_*(map, key)Remove
hashmap_clear_*(map)Clear all entries
hashmap_size_*(map)Get size

Example

var scores = HashMap<String, Int>()
scores.insert("Alice", 95)
scores.insert("Bob", 87)
scores.insert("Charlie", 92)

let alice = scores.get("Alice")
if alice.isSome() {
    println("Alice's score: {alice.unwrap()}")
}

BTreeMap<K, V>

Ordered map based on B-tree. Keys are kept sorted.

import collections.btree_map

Same interface as HashMap, but with ordered iteration.

Runtime BTreeMap Functions

4 variants (int_int, int_str, str_int, str_str):

FunctionDescription
btreemap_new_*()Create new map
btreemap_insert_*(map, key, val)Insert (maintains order)
btreemap_get_*(map, key)Lookup
btreemap_remove_*(map, key)Remove
btreemap_clear_*(map)Clear
btreemap_size_*(map)Size

HashSet<T>

Unordered set backed by HashMap<T, Unit>.

import collections.hashset

BTreeSet<T>

Ordered set backed by BTreeMap<T, Unit>.

import collections.btree_set

LinkedList<T>

Doubly-linked list.

import collections.linked_list

Methods

MethodReturnDescription
push_front(value: T)VoidAdd to front
push_back(value: T)VoidAdd to back
pop_front()TRemove from front
pop_back()TRemove from back
len()IntLength

Runtime LinkedList Functions

2 variants (int, str):

FunctionDescription
linkedlist_new_*()Create new list
linkedlist_push_front_*(list, val)Push front
linkedlist_push_back_*(list, val)Push back
linkedlist_pop_front_*(list)Pop front
linkedlist_pop_back_*(list)Pop back
linkedlist_size_*(list)Size

VecDeque<T>

Double-ended queue with O(1) front/back operations.

import collections.vecdeque

collections/vecdeque currently exposes IntVecDeque for integer queues.

SmallVec<T>

Inline-storage vector that avoids heap allocation for small sizes:

let sv = seen_small_vec_new(8)   // inline capacity of 8
seen_small_vec_push_i64(sv, 42)
let val = seen_small_vec_get_i64(sv, 0)
let len = seen_small_vec_length(sv)
seen_small_vec_clear(sv)

Falls back to heap when inline capacity is exceeded.

StringHashMap<V>

Optimized HashMap<String, V> with string-specific hashing.

import collections.string_hash_map

ByteBuffer

Low-level byte storage for binary data. ByteArray and ByteBuffer use compact runtime-backed byte storage and expose Int values at the API boundary.

import collections.byte_buffer

let bytes = ByteBuffer.withCapacity(1024)
bytes.reserve(4096)
bytes.push(255)
bytes.push(256)   // stored as 0
let value = bytes.get(0)

Byte APIs

TypeDescription
ByteArrayCompact growable byte array
ByteBufferConvenience wrapper around ByteArray
Int32Buffer / Int64BufferPrimitive integer buffer APIs backed by compact runtime storage
Float32Buffer / Float64BufferPrimitive floating-point buffer APIs backed by native float/double storage
MethodReturnDescription
capacity()IntCurrent allocated capacity
tryReserve(requiredCapacity)BoolGrow backing storage without aborting on allocation failure
reserve(requiredCapacity)VoidGrow backing storage or panic with a Seen diagnostic
push(value: Int)VoidAppend byte, masked to 0..255
append(other)VoidAppend another byte buffer
get(index: Int)IntRead byte
set(index: Int, value: Int)VoidWrite byte
slice(start: Int, end: Int)same typeCopy a byte range
reverse()VoidReverse in place
fill(value: Int)VoidFill existing bytes
toArray() / toIntArray()Array<Int>Convert to integer byte values

Algorithms

Shared collection algorithms for performance-sensitive integer and floating-point paths.

import collections.algorithms

Module path: collections/algorithms.

Function / TypeDescription
binarySearchInt(values, needle)Return matching index or -1
lowerBoundInt(values, needle)First insertion slot not less than needle
upperBoundInt(values, needle)First insertion slot greater than needle
unstableSortInt(values)In-place introsort with insertion sort for small partitions and a heapsort depth fallback
stableSortInt(values)Stable sorted copy
radixSortInt(values)Signed integer radix sort that preserves negative/positive ordering
IntPriorityQueue.min() / .max()Binary heap priority queues
binarySearchFloat(values, needle)Return matching float index or -1
lowerBoundFloat(values, needle)First float insertion slot not less than needle
upperBoundFloat(values, needle)First float insertion slot greater than needle
unstableSortFloat(values)In-place introsort for Array<Float>
stableSortFloat(values)Stable sorted float copy
FloatPriorityQueue.min() / .max()Binary heap priority queues for floats

BitSet

Compact bit set.

import collections.bit_set

StringBuffer

Mutable string buffer used by parser, compiler, and text-heavy runtime code.

import collections.string_buffer

StdString

collections/std_string provides StdString, a stdlib wrapper around string operations that need a class-style surface.

Pool<T>

Object pool for reusing allocated objects.

import collections.pool
Architected in Kotlin. Rendered with Materia. Powered by Aether.
© 2026 Yousef.