Standard library
Map
Hash map with mixed keys.
Introduction
Hash map with mixed keys. Import std/collections/map to bind the module as map. Call free functions as map.name(...). Struct methods use a receiver value.
/ std/collections/map
This page is the package reference for std/collections/map. Private helpers used only by co-located tests are not listed.
Struct · map
Map shape with put and get methods. The shape is exported as map.map. Methods on the receiver are listed next.
/ std/collections/map
; shape: map.map
$ m = map.make()
Parameters: No parameters. Type or shape export. Returns: Shape export used for literals and methods.
map · seed
Sets SipHash key halves on an empty map for fluent make().seed(...). Reseeding a non-empty map fails with a result err. Call form: map.seed(k0, k1).
/ std/collections/map
$ m = map.make()
| m.seed(1, 2) {
$ _ { }
! e { }
}Parameters: k0: first key half. k1: second key half. Returns: Result. Ok arm: the map receiver. Err arm: "cannot reseed non-empty map".
map · put
Inserts or replaces the value for key and returns the map for chaining. Call form: map.put(key, value).
/ std/collections/map
$ m = map.make()
m.put("a", 1)Parameters: key: map key. value: value to store. Returns: The map receiver.
map · get
Looks up key. Missing keys use the option none arm. Call form: map.get(key).
/ std/collections/map
$ m = map.make()
m.put("a", 1)
| m.get("a") {
$ v { }
: { }
}Parameters: key: map key. Returns: Option. Some arm: stored value. None arm: missing key.
map · remove
Removes key if present and returns the previous value as an option. Call form: map.remove(key).
/ std/collections/map
$ m = map.make()
m.put("a", 1)
| m.remove("a") {
$ v { }
: { }
}Parameters: key: map key. Returns: Option. Some arm: removed value. None arm: key was absent.
map · has
Reports whether key is present. Call form: map.has(key).
/ std/collections/map
$ m = map.make()
$ ok = m.has("a")Parameters: key: map key. Returns: Boolean.
map · len
Returns the number of entries in the map. Call form: map.len().
/ std/collections/map
$ m = map.make()
$ n = m.len()
Parameters: No parameters. Returns: Integer length.
map · is_empty
Reports whether the map has no entries. Call form: map.is_empty().
/ std/collections/map
$ m = map.make()
$ empty = m.is_empty()
Parameters: No parameters. Returns: Boolean.
map · keys
Returns a snapshot list of keys. Order is undefined. Call form: map.keys().
/ std/collections/map
$ m = map.make()
$ ks = m.keys()
Parameters: No parameters. Returns: List of keys.
map · values
Returns a snapshot list of values. Order is undefined. Call form: map.values().
/ std/collections/map
$ m = map.make()
$ vs = m.values()
Parameters: No parameters. Returns: List of values.
map · entries
Returns a snapshot list of { key, value } products. Order is undefined. Call form: map.entries().
/ std/collections/map
$ m = map.make()
$ es = m.entries()
Parameters: No parameters. Returns: List of entry products.
map · to_list
Returns the same snapshot as entries(), for for-in over the map. Call form: map.to_list().
/ std/collections/map
$ m = map.make()
m.put(1, 2)
* e : m.to_list() { }Parameters: No parameters. Returns: List of entry products.
map · hash_key
Hashes key with the map's SipHash seed (low-level helper). Call form: map.hash_key(key).
/ std/collections/map
$ m = map.make()
$ h = m.hash_key("a")Parameters: key: map key. Returns: Integer hash.
map · bucket_index
Returns the bucket index for key under the current capacity. Call form: map.bucket_index(key).
/ std/collections/map
$ m = map.make()
$ i = m.bucket_index("a")Parameters: key: map key. Returns: Integer bucket index.
Functions
Free functions on map. Each function has a short description, an example, then parameters and return shape.
make
Creates an empty map. Call form: map.make().
/ std/collections/map
$ m = map.make()
Parameters: No parameters. Returns: Empty map value.
from_indexed
Builds a map from an indexed list of pairs. Call form: map.from_indexed(ls).
/ std/collections/map
$ m = map.from_indexed([{ key: "a", value: 1 }])Parameters: pairs: list of key/value products. Returns: Map value.