tur/map
typed Map[K V]: persistent hash map requiring Hash[K] and Eq[K].
Since: Phase TM0
Map
(defstruct Map [K V])
parameterized persistent map with key type K and value type V.
Since: Phase TM0
map-new
(map-new)
create a new empty typed map.
An empty Map[K V].
(map-new) ; => empty Map
Since: Phase TM0
map-hamt
(map-hamt [m :int])
internal accessor for the HAMT backing store.
map-wrap
(map-wrap [h :ptr<void>])
internal constructor from a HAMT pointer.
map-assoc
(map-assoc [m :int key :int val :int])
insert or update a key/value pair; returns a new map.
| m | source Map[K V] | |
| key | key of type K (used as hash for scalar keys) | |
| val | value of type V |
A new Map[K V] with the entry inserted or updated.
(map-assoc my-map 1 100) ; => updated map
Since: Phase TM0
map-assoc-h
(map-assoc-h [m :int h :int key :int val :int])
insert or update with an explicit hash; returns a new map.
| m | source Map[K V] | |
| h | precomputed hash of key (from Hash[K] typeclass) | |
| key | key of type K | |
| val | value of type V |
A new Map[K V] with the entry inserted or updated.
(map-assoc-h my-map (hash k) k v) ; => updated map
Since: Phase TM0
map-dissoc
(map-dissoc [m :int h :int key :int])
remove a key from the map; returns a new map.
| m | source Map[K V] | |
| h | precomputed hash of key | |
| key | key of type K |
A new Map[K V] with the key removed.
(map-dissoc my-map (hash k) k) ; => map without k
Since: Phase TM0
map-get
(map-get [m :int h :int key :int])
look up a key; returns the value or 0 if absent.
| m | Map[K V] | |
| h | precomputed hash of key | |
| key | key of type K |
The value for the key, or 0 (none) if absent.
(map-get my-map (hash k) k) ; => value or 0
Since: Phase TM0
map-has?
(map-has? [m :int h :int key :int])
check whether a key exists in the map.
| m | Map[K V] | |
| h | precomputed hash of key | |
| key | key of type K |
true if the key is present, false otherwise.
(map-has? my-map (hash k) k) ; => true or false
Since: Phase TM0
map-count
(map-count [m :int])
return the number of entries in the map.
| m | Map[K V] |
Integer count of key/value pairs.
(map-count my-map) ; => 3
Since: Phase TM0
map-merge
(map-merge [a :int b :int])
merge two maps; values from b win on key collision.
| a | first Map[K V] | |
| b | second Map[K V] (wins on collision) |
A new Map[K V] containing all entries from both maps.
(map-merge map-a map-b) ; => merged map
Since: Phase TM0
map-free
(map-free [m :int])
free the Map wrapper (does not free HAMT; use map-free-all for that).
| m | Map[K V] to free |
(map-free my-map)
Since: Phase TM0
map-eq?
(map-eq? [m1 :int m2 :int val-cmp])
compare two maps for structural equality using a value comparator.
| m1 | first Map[K V] | |
| m2 | second Map[K V] | |
| val-cmp | comparator fn [a :int b :int] :bool applied to each value pair |
true if both maps have identical keys and all corresponding values satisfy val-cmp.
(map-eq? ma mb (fn [a b] (= a b))) ; => true
Since: Phase TM0
Eq[Map]
(definstance Eq [Map])
structural equality using the value type's Eq instance.