No matching definitions.

tur/mutmap

stdlib/mutmap.tur

MutableMap[K V]: mutable open-addressed hash table.

Since: Phase F5

defstruct

MutableMap

(defstruct MutableMap [K V])

parameterized in-place hash table with key K, value V.

Since: Phase F5 (cross-plan-followups)

defn

mutmap-new

(mutmap-new [K V])

create a new empty MutableMap[K V] with default

An empty MutableMap[K V]. K/V are inferred from later use (e.g. the first mutmap-set!), like vec-new's element type.

(mutmap-new)  ; => empty MutableMap

Since: Phase F5

defn

mutmap-len

(mutmap-len [K V])

live entry count (excludes tombstones).

mMutableMap[K V]

Number of live (key, value) entries.

(mutmap-len mm)  ; => 0

Since: Phase F5

defn

mutmap-set!

(mutmap-set! [K V])

insert or update (key, value). Mutates m in place.

mMutableMap[K V]
hprecomputed hash of key (Hash[K])
keykey
valvalue

nil.

(mutmap-set! mm 1 1 100)

Since: Phase F5

defn

mutmap-get

(mutmap-get [K V])

look up the value bound to key, or 0 if absent.

mMutableMap[K V]
hprecomputed hash of key (Hash[K])
keykey

The bound value, or 0 if key is not present. Callers needing to distinguish "absent" from "value = 0" should use mutmap-has? first.

(mutmap-get mm 1 1)  ; => 100

Since: Phase F5

defn

mutmap-has?

(mutmap-has? [K V])

check whether key is present.

mMutableMap[K V]
hprecomputed hash of key
keykey

true if key is present (value of any kind), false otherwise.

(mutmap-has? mm 1 1)  ; => true

Since: Phase F5

defn

mutmap-delete!

(mutmap-delete! [K V])

remove (key, value) if present. Mutates m

mMutableMap[K V]
hprecomputed hash of key
keykey

true if key was present (and is now removed), false otherwise.

(mutmap-delete! mm 1 1)  ; => true

Since: Phase F5

defn

mutmap-cap

(mutmap-cap [K V])

slot-array capacity (number of probe slots, a power of two).

mMutableMap[K V]

The backing storage capacity (>= mutmap-len; includes EMPTY and DELETED slots). Used as the iteration bound for mutmap-slot-* walks.

(mutmap-cap mm)  ; => 16

Since: Phase F5

defn

mutmap-slot-occupied?

(mutmap-slot-occupied? [K V])

is slot i a live (OCCUPIED) entry?

mMutableMap[K V]
islot index in [0, mutmap-cap m)

true iff slot i holds a live entry (not EMPTY, not a DELETED tombstone).

(mutmap-slot-occupied? mm 0)  ; => true / false

Since: Phase F5

defn

mutmap-slot-hash

(mutmap-slot-hash [K V])

precomputed hash stored in slot i.

mMutableMap[K V]
islot index in [0, mutmap-cap m)

The hash recorded for slot i (meaningful only when the slot is OCCUPIED).

(mutmap-slot-hash mm 0)

Since: Phase F5

defn

mutmap-slot-key

(mutmap-slot-key [K V])

key stored in slot i.

mMutableMap[K V]
islot index in [0, mutmap-cap m)

The key in slot i (meaningful only when the slot is OCCUPIED).

(mutmap-slot-key mm 0)

Since: Phase F5

defn

mutmap-slot-value

(mutmap-slot-value [K V])

value stored in slot i.

mMutableMap[K V]
islot index in [0, mutmap-cap m)

The value in slot i (meaningful only when the slot is OCCUPIED).

(mutmap-slot-value mm 0)

Since: Phase F5

defn

mutmap-eq-storage?

(mutmap-eq-storage? [pa ptr<void> pb ptr<void> ^fat val-cmp])

structural equality over two raw storage pointers.

defn

mutmap-eq-loop

(mutmap-eq-loop [K V])

pure-Turmeric structural-equality walk (self-tail slot loop).

m1first MutableMap[K V]
m2second MutableMap[K V]
icurrent slot index (start at 0)
capslot bound (mutmap-cap m1)
val-cmpvalue comparator fn [a :V b :V] :bool

true iff every live entry of m1[i..cap) is present in m2 with an equal value under val-cmp.

(mutmap-eq-loop a b 0 (mutmap-cap a) (fn [x y] (= x y)))

Since: Phase F5

defn

mutmap-eq?

(mutmap-eq? [K V])

structural equality. Two MutableMap[K V]s are equal iff

m1MutableMap[K V]
m2MutableMap[K V]
val-cmpcomparator fn [a :int b :int] :bool for values

true iff m1 and m2 have the same set of (key, value) pairs.

(mutmap-eq? ma mb (fn [a b] (= a b)))

Since: Phase F5

defn

mutmap-free

(mutmap-free [K V])

free the storage and wrapper.

mMutableMap[K V] to free
(mutmap-free mm)

Since: Phase F5

definstance

Eq[MutableMap]

(definstance Eq [MutableMap])

structural equality using the value type's Eq.