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;
3
4fn main() -> void {
5 // 1. Dynamic List
6 List<string> cities = new List<string>();
7 cities.add("Tokyo");
8 cities.add("London");
9 cities.add("New York");
10
11 // 2. Hash Map
12 Map<string, int> pop = new Map<string, int>();
13 pop.set("Tokyo", 14000000);
14 pop.set("London", 9000000);
15
16 println("Cities count: ${cities.size()}");
17 println("Tokyo population: ${pop.get('Tokyo')}");
18}

Collection Primitives

List<T>

Native Builtin
class 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 Builtin
class 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.