std.collections Reference
The std.collections module provides dynamically resizable data structures: List<T>, Map<K, V>, and Set<T>.
collections_example.sp
1import std.io;2import std.collections;34fn main() -> void {5 // 1. Dynamic List6 List<string> cities = new List<string>();7 cities.add("Tokyo");8 cities.add("London");9 cities.add("New York");1011 // 2. Hash Map12 Map<string, int> pop = new Map<string, int>();13 pop.set("Tokyo", 14000000);14 pop.set("London", 9000000);1516 println("Cities count: ${cities.size()}");17 println("Tokyo population: ${pop.get('Tokyo')}");18}
Collection Primitives
List<T>
Native Builtinclass List<T> { fn add(T item) -> void; fn get(int index) -> T; fn size() -> int; fn clear() -> void; }
Dynamic resizable vector with amortized O(1) appending and contiguous memory layout.
Map<K, V>
Native Builtinclass Map<K, V> { fn set(K key, V val) -> void; fn get(K key) -> V?; fn containsKey(K key) -> bool; fn remove(K key) -> void; }
High-performance hash table with robin-hood hashing and linear probing.