Standard library
Hash table
Lower-level hash table.
Introduction
Lower-level hash table. Import std/collections/hash_table to bind the module as hash_table. Call free functions as hash_table.name(...). Struct methods use a receiver value.
/ std/collections/hash_table
This page is the package reference for std/collections/hash_table. Private helpers used only by co-located tests are not listed.
Struct · hash_table
Hash table shape used with hash_table.make and table methods. The shape is exported as hash_table.hash_table. Methods on the receiver are listed next.
/ std/collections/hash_table
; shape: hash_table.hash_table
$ t = hash_table.make()
Parameters: No parameters. Type or shape export. Returns: Shape export used for literals and methods.
hash_table · len
Returns the number of live key/value entries. Call form: hash_table.len().
/ std/collections/hash_table
$ t = hash_table.make()
$ n = t.len()
Parameters: No parameters. Returns: Integer count.
hash_table · is_empty
Reports whether the table has no entries. Call form: hash_table.is_empty().
/ std/collections/hash_table
$ t = hash_table.make()
$ empty = t.is_empty()
Parameters: No parameters. Returns: Boolean.
hash_table · seed
Sets SipHash key halves in place. Returns the table for fluent make().seed(...). Call form: hash_table.seed(k0, k1).
/ std/collections/hash_table
$ t = hash_table.make()
t.seed(1, 2)
Parameters: k0: first key half. k1: second key half. Returns: The hash_table receiver.
hash_table · put
Inserts or replaces the value for key. Grows the table when load is high. Call form: hash_table.put(key, value).
/ std/collections/hash_table
$ t = hash_table.make()
t.put("a", 1)Parameters: key: key value. value: stored value. Returns: The hash_table receiver.
hash_table · get
Looks up key. Missing keys use the option none arm. Call form: hash_table.get(key).
/ std/collections/hash_table
$ t = hash_table.make()
t.put("a", 1)
| t.get("a") {
$ v { }
: { }
}Parameters: key: key value. Returns: Option. Some arm: stored value. None arm: missing key.
hash_table · remove
Removes key if present and returns the previous value as an option. Call form: hash_table.remove(key).
/ std/collections/hash_table
$ t = hash_table.make()
| t.remove("a") {
$ v { }
: { }
}Parameters: key: key value. Returns: Option. Some arm: removed value. None arm: key was absent.
hash_table · has
Reports whether key is present. Call form: hash_table.has(key).
/ std/collections/hash_table
$ t = hash_table.make()
$ ok = t.has("a")Parameters: key: key value. Returns: Boolean.
hash_table · keys
Returns a snapshot list of keys. Order is undefined. Call form: hash_table.keys().
/ std/collections/hash_table
$ t = hash_table.make()
$ ks = t.keys()
Parameters: No parameters. Returns: List of keys.
hash_table · values
Returns a snapshot list of values. Order is undefined. Call form: hash_table.values().
/ std/collections/hash_table
$ t = hash_table.make()
$ vs = t.values()
Parameters: No parameters. Returns: List of values.
hash_table · entries
Returns a snapshot list of entry products. Order is undefined. Call form: hash_table.entries().
/ std/collections/hash_table
$ t = hash_table.make()
$ es = t.entries()
Parameters: No parameters. Returns: List of entry products.
hash_table · hash_key
Hashes key with the table's SipHash seed. Call form: hash_table.hash_key(key).
/ std/collections/hash_table
$ t = hash_table.make()
$ h = t.hash_key("a")Parameters: key: key value. Returns: Integer hash.
hash_table · bucket_index
Returns the bucket index for key under the current capacity. Call form: hash_table.bucket_index(key).
/ std/collections/hash_table
$ t = hash_table.make()
$ i = t.bucket_index("a")Parameters: key: key value. Returns: Integer bucket index.
Functions
Free functions on hash_table. Each function has a short description, an example, then parameters and return shape.
make
Creates an empty hash table. Call form: hash_table.make().
/ std/collections/hash_table
$ t = hash_table.make()
Parameters: No parameters. Returns: Empty hash table value.