Map
is a hashmap datatype, i.e. a key-value structure. It allows you to put in pairs of keys and values and look them up by key.
Implementation notes: it is a dense double-array-backed structure that grows and shrinks based on load.
all?
(Fn [(Ref (Fn [(Ref a b), (Ref c b)] Bool d) e), (Ref (Map a c) b)] Bool)
(all? pred m)
Do all key-value pairs pass the given predicate (of two arguments)?
buckets
(Fn [(Ref (Map a b) c)] (Ref (Array (Bucket a b)) c))
gets the buckets
property of a Map
.
contains?
(Fn [(Ref (Map a b) c), (Ref a c)] Bool)
(contains? m k)
Check whether the map m contains the key k.
endo-map
(Fn [(Ref (Fn [(Ref a b), (Ref c b)] c d) e), (Map a c)] (Map a c))
(endo-map f m)
Transform values of the given map in place. f gets two arguments, key and value, and should return new value
for-each
(Fn [(Ref (Map a b) c), (Ref (Fn [(Ref a c), (Ref b c)] () d) e)] ())
(for-each m f)
Execute the binary function f for all keys and values in the map m.
from-array
(Fn [(Array (Pair a b))] (Map a b))
(from-array a)
Create a map from the array a containing key-value pairs.
get
(Fn [(Ref (Map a b) c), (Ref a c)] b)
(get m k)
Get the value for the key k from map m. If it isn’t found, a zero element for the value type is returned.
get-maybe
(Fn [(Ref (Map a b) c), (Ref a c)] (Maybe b))
(get-maybe m k)
Get the value for the key k from map m. It returns a Maybe type, meaning that if nothing is found, Nothing is returned.
get-with-default
(Fn [(Ref (Map a b) c), (Ref a c), (Ref b d)] b)
(get-with-default m k default-value)
Get the value for the key k from map m. If it isn’t found, the default is returned.
grow
(Fn [(Map a b)] (Map a b))
(grow m)
Grow a map m
. Should usually be handled automatically.
keys
(Fn [(Ref (Map a b) c)] (Array a))
(keys m)
Return an array of the keys of the map. Order corresponds to order of (vals m)
kv-reduce
(Fn [(Ref (Fn [a, (Ref b c), (Ref d c)] a e) f), a, (Ref (Map b d) c)] a)
(kv-reduce f init m)
Reduce a map with a function of three arguments: state, key and value. Reduction order is not guaranteed.
merge
(Fn [(Map a b), (Ref (Map a b) c)] (Map a b))
(merge m1 m2)
Merge two maps m1
and m2
. On collision the value from m2
is preferred.
put
(Fn [(Map a b), (Ref a c), (Ref b c)] (Map a b))
(put m k v)
Put a value v into map m, using the key k.
put!
(Fn [(Ref (Map a b) c), (Ref a c), (Ref b d)] ())
(put! m k v)
Put a value v into map m, using the key k, in place.
remove
(Fn [(Map a b), (Ref a c)] (Map a b))
(remove m k)
Remove the value under the key k from the map m.
reverse
(Fn [(Ref (Map a b) c)] (Map b a))
(reverse m)
reverses they keys and values in a given map m
.
set-buckets
(Fn [(Map a b), (Array (Bucket a b))] (Map a b))
sets the buckets
property of a Map
.
set-buckets!
(Fn [(Ref (Map a b) c), (Array (Bucket a b))] ())
sets the buckets
property of a Map
in place.
set-n-buckets!
(Fn [(Ref (Map a b) c), Int] ())
sets the n-buckets
property of a Map
in place.
shrink
(Fn [(Map a b)] (Map a b))
(shrink m)
Shrink a map m
. Should usually be handled automatically.
to-array
(Fn [(Ref (Map a b) c)] (Array (Pair a b)))
(to-array m)
Convert Map to Array of Pairs
update
(Fn [(Map a b), (Ref a c), (Ref (Fn [b] b d) c)] (Map a b))
(update m k f)
Update value at key k in map with function f, if it exists.
update-buckets
(Fn [(Map a b), (Ref (Fn [(Array (Bucket a b))] (Array (Bucket a b)) c) d)] (Map a b))
updates the buckets
property of a (Map a b)
using a function f
.
update-len
(Fn [(Map a b), (Ref (Fn [Int] Int c) d)] (Map a b))
updates the len
property of a (Map a b)
using a function f
.
update-n-buckets
(Fn [(Map a b), (Ref (Fn [Int] Int c) d)] (Map a b))
updates the n-buckets
property of a (Map a b)
using a function f
.
update-with-default
(Fn [(Map a b), (Ref a c), (Ref (Fn [b] b d) c), b] (Map a b))
(update-with-default m k f v)
Update value at key k in map with function f. If k doesn't exist in map, set k to (f v).
update-with-default!
(Fn [(Ref (Map a b) c), (Ref a c), (Ref (Fn [b] b d) e), b] ())
(update-with-default! m k f v)
Update value at key k in map with function f, in-place. If k doesn't exist in map, set k to (f v).
vals
(Fn [(Ref (Map a b) c)] (Array b))
(vals m)
Return an array of the values of the map. Order corresponds to order of (keys m)