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.

=

defn

(Fn [(Ref (Map a b) c), (Ref (Map a b) c)] Bool)

                        (= m1 m2)
                    

all?

defn

(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

instantiate

(Fn [(Ref (Map a b) c)] (Ref (Array (Bucket a b)) c))

gets the buckets property of a Map.

contains?

defn

(Fn [(Ref (Map a b) c), (Ref a c)] Bool)

                        (contains? m k)
                    

Check whether the map m contains the key k.

copy

template

(Fn [(Ref (Map a b) c)] (Map a b))

copies a Map.

create

defn

(Fn [] (Map a b))

                        (create)
                    

Create an empty map.

delete

template

(Fn [(Map a b)] ())

deletes a Map. Should usually not be called manually.

empty?

defn

(Fn [(Ref (Map a b) c)] Bool)

                        (empty? m)
                    

Check whether the map m is empty.

endo-map

defn

(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

defn

(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

defn

(Fn [(Array (Pair a b))] (Map a b))

                        (from-array a)
                    

Create a map from the array a containing key-value pairs.

get

defn

(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

defn

(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

defn

(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

defn

(Fn [(Map a b)] (Map a b))

                        (grow m)
                    

Grow a map m. Should usually be handled automatically.

init

template

(Fn [Int, Int, (Array (Bucket a b))] (Map a b))

creates a Map.

keys

defn

(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

defn

(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.

len

instantiate

(Fn [(Ref (Map a b) c)] (Ref Int c))

gets the len property of a Map.

length

defn

(Fn [(Ref (Map a b) c)] Int)

                        (length m)
                    

Get the length of the map m.

max-load

def

Int

The load a map needs to reach in order to grow.

merge

defn

(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.

min-load

def

Int

The load a map needs to reach in order to shrink.

n-buckets

instantiate

(Fn [(Ref (Map a b) c)] (Ref Int c))

gets the n-buckets property of a Map.

prn

template

(Fn [(Ref (Map a b) c)] String)

converts a Map to a string.

put

defn

(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!

defn

(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

defn

(Fn [(Map a b), (Ref a c)] (Map a b))

                        (remove m k)
                    

Remove the value under the key k from the map m.

resize

defn

(Fn [(Map a b), Int] (Map a b))

                        (resize m s)
                    

Resize a map m to size s.

reverse

defn

(Fn [(Ref (Map a b) c)] (Map b a))

                        (reverse m)
                    

reverses they keys and values in a given map m.

set-buckets

template

(Fn [(Map a b), (Array (Bucket a b))] (Map a b))

sets the buckets property of a Map.

set-buckets!

template

(Fn [(Ref (Map a b) c), (Array (Bucket a b))] ())

sets the buckets property of a Map in place.

set-len

instantiate

(Fn [(Map a b), Int] (Map a b))

sets the len property of a Map.

set-len!

instantiate

(Fn [(Ref (Map a b) c), Int] ())

sets the len property of a Map in place.

set-n-buckets

instantiate

(Fn [(Map a b), Int] (Map a b))

sets the n-buckets property of a Map.

set-n-buckets!

instantiate

(Fn [(Ref (Map a b) c), Int] ())

sets the n-buckets property of a Map in place.

shrink

defn

(Fn [(Map a b)] (Map a b))

                        (shrink m)
                    

Shrink a map m. Should usually be handled automatically.

str

defn

(Fn [(Ref (Map a b) c)] String)

                        (str m)
                    

converts a Map to a string.

to-array

defn

(Fn [(Ref (Map a b) c)] (Array (Pair a b)))

                        (to-array m)
                    

Convert Map to Array of Pairs

update

defn

(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

instantiate

(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

instantiate

(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

instantiate

(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

defn

(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!

defn

(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

defn

(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)