Std.HashMap

import Std.HashMap

Source


Types


HashMap

type HashMap k v =
    len: Usz
    capacity: Usz
    entries: Ptr (Entry k v)

A linear-scan mutable HashMap using a resize factor of 2.0

source


HashMap.len

HashMap.len (m: ref HashMap k v): Usz

Returns the length of this HashMap

source


HashMap.is_empty

HashMap.is_empty (m: ref HashMap k v): Bool

Returns true if this HashMap is empty. Equivalent to map.len () == 0

source


HashMap.empty

(HashMap.empty: fn Unit -> HashMap _ _ is pure) ()

Create a new, empty HashMap This will not allocate until the first entry is inserted.

source


HashMap.of

HashMap.of (s: s) {_: Stream s (k, v) e} {_: Hash k} {_: Eq k e}: HashMap k v can Panic, e

Create a HashMap containing each k, v pair from the given stream.

source


HashMap.extend

HashMap.extend (map: mut HashMap k v) (s: s) {_: Stream s (k, v) e} {_: Hash k} {_: Eq k e}: Unit can Panic, e

source


HashMap.clear

HashMap.clear (map: mut HashMap k v): Unit

source


HashMap.resize

HashMap.resize (map: mut HashMap k v) (new_capacity: Usz) {_: Hash k} {_: Eq k e}: Unit can Panic, e

source


HashMap.should_resize

HashMap.should_resize (map: ref HashMap k v): Bool

Should we resize this map when pushing another element?

source


HashMap.insert

HashMap.insert (map: mut HashMap k v) (key: k) (value: v) {_: Hash k} {_: Eq k e}: Maybe v can Panic, e

Inserts a key-value pair into the map, removing any item that may previously have been associated with the same key and returning the removed value if there was one.

source


HashMap.get_entry

HashMap.get_entry (map: ref 'm HashMap k v) (key: ref k) {_: Hash k} {eq: Eq k e}: Maybe (ref 'm Entry k v) can e

source


HashMap.get

HashMap.get (map: ref 'm HashMap k v) (key: ref k) {_: Hash k} {_: Eq k e}: ref 'm v can Fail, e

source


HashMap.contains

HashMap.contains (map: ref HashMap k v) (key: ref k) {_: Hash k} {_: Eq k e}: Bool can e

source


HashMap.remove

HashMap.remove (map: mut HashMap k v) (key: ref k) {_: Hash k} {_: Eq k e}: Maybe v can e

source


HashMap.keys

(HashMap.keys: fn (ref (HashMap k v)) -> (fn Unit [(ref (HashMap k v))] -> Unit can Emit k) is pure) (m: ref (HashMap k v))

Emit each key. Bit-copies the key; safe for Copy keys.

source


HashMap.values

(HashMap.values: fn (ref (HashMap k v)) -> (fn Unit [(ref (HashMap k v))] -> Unit can Emit v) is pure) (m: ref (HashMap k v))

Emit each value. Bit-copies the value; safe for Copy values.

source


HashMap.get_or_insert

HashMap.get_or_insert (m: mut HashMap k v) (key: k) (default: v) {_: Hash k} {_: Eq k e} {_: Copy k}: ref v can Panic, e

Return the existing value at key, or insert default and return it.

source


HashMap.get_or_insert_with

HashMap.get_or_insert_with (m: mut HashMap k v) (key: k) (mk: fn Unit [_] -> v) {_: Hash k} {_: Eq k e} {_: Copy k}: ref v can Panic, e

Same as get_or_insert but builds the default lazily.

source


HashMap.retain

HashMap.retain (m: mut HashMap k v) (pred: fn k v [_] -> Bool) {_: Copy k} {_: Copy v}: Unit

Remove every entry for which pred key value returns false.

source


HashMap.merge

HashMap.merge (dst: mut HashMap k v) (src: HashMap k v) {_: Hash k} {_: Eq k e}: Unit can Panic, e

Insert every entry from src into dst, overwriting on conflict.

source


Entry

type Entry k v =
    key: k
    value: v
    occupied: Bool
    tombstone: Bool

source


Implicits


Show Implicits
impl print_hashmap {_: Display k e} {_: Display v e}: Display (HashMap k v) e

source


stream_map

implicit stream_map: Stream (HashMap k v) (k, v) pure

source