Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

CreateHashMap

Creates an empty hash map using built-in logical key hashing.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. Read the status →

Module std.collections

import std.collections;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

CreateHashMap

pub fn CreateHashMap<K, V>() -> HashMap<K, V>
    where K: BuiltinHashKey, Movable where V: Movable

Creates an empty hash map using built-in logical key hashing.

Construction allocates nothing. The returned owner allocates on fallible reserve/insertion; borrowed text keys still require their backing owner to outlive storage. Custom key types must supply an explicit policy through the HashMap constructor. Floating keys use canonical signed-zero/NaN equality. K: Supported built-in key representation, movable into storage. V: Movable owned value representation. Return: Empty owning table with the default allocator and safe hash functions.

CreateHashMap

pub fn CreateHashMap<K, V, A>(mut AllocatorValue: A) -> HashMap<K, V, HashPolicy<K>, A>
    where K: BuiltinHashKey, Movable where V: Movable where A: Allocator, Defaultable, Movable

Creates an empty default-hash map with a transferred allocator.

Both table arrays remain owned by this allocator; failed insertion retains the input key and value. Construction allocates nothing and retains no external borrow. K: Supported built-in movable key representation. V: Movable owned value representation. A: Movable Defaultable allocator type owning future table allocations. AllocatorValue: Allocator transferred into the returned table. Return: Empty table owning its allocator and default safe hash/equality policy.

Example

module example.default_hash_allocator;
from std.collections import CreateHashMap, CreateHashSet;
from std.memory import DefaultAllocator;
fn Main() -> i32 {
    var Values = CreateHashMap<u32, i32>(default(DefaultAllocator));
    var Keys = CreateHashSet<u32>(default(DefaultAllocator));
    if Values.TryReserve(2) is .Err { Error = _ } { return 1; }
    if Keys.TryReserve(2) is .Err { Error = _ } { return 2; }
    if Values.TryInsert(7, 42) is .Err { Error = _ } { return 3; }
    if Keys.TryInsert(7) is .Err { Error = _ } { return 4; }
    if !Keys.Contains(7) || Values.Find(7).Unwrap() != 42 { return 5; }
    Values.Clear(); Keys.Clear();
    if Values.TryShrinkToFit() is .Err { Error = _ } { return 6; }
    if Keys.TryShrinkToFit() is .Err { Error = _ } { return 7; }
    return 0;
}
Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library