tur/hamt

stdlib/hamt.tur
defn

hamt/new

(hamt/new :ptr<void>)

create a new empty persistent HAMT.

Since: Phase P1

defn

hamt/free

(hamt/free [m :ptr<void>] :void)

decrement the reference count of a HAMT; free if it reaches zero.

mHAMT pointer

Since: Phase P1

defn

hamt/retain

(hamt/retain [m :ptr<void>] :ptr<void>)

increment the reference count of a HAMT and return it.

mHAMT pointer

Since: Phase P1

defn

hamt/set

(hamt/set [m :ptr<void> hash :int key :ptr<void> val :ptr<void>] :ptr<void>)

insert or update a key/value pair; returns a new HAMT.

msource HAMT pointer
hash64-bit hash of the key (passed as int64_t)
keykey pointer
valvalue pointer

Since: Phase P1

defn

hamt/del

(hamt/del [m :ptr<void> hash :int key :ptr<void>] :ptr<void>)

delete a key from the HAMT; returns a new HAMT.

msource HAMT pointer
hash64-bit hash of the key
keykey pointer

Since: Phase P1

defn

hamt/get

(hamt/get [m :ptr<void> hash :int key :ptr<void>] :ptr<void>)

look up a key and return its value, or NULL if absent.

mHAMT pointer
hash64-bit hash of the key
keykey pointer

Since: Phase P1

defn

hamt/has?

(hamt/has? [m :ptr<void> hash :int key :ptr<void>] :bool)

check whether a key exists in the HAMT.

mHAMT pointer
hash64-bit hash of the key
keykey pointer

Since: Phase P1

defn

hamt/count

(hamt/count [m :ptr<void>] :int)

return the number of key/value pairs in the HAMT.

mHAMT pointer

Since: Phase P1

defn

hamt/merge

(hamt/merge [a :ptr<void> b :ptr<void>] :ptr<void>)

merge two HAMTs; values from b win on key collision.

afirst HAMT pointer
bsecond HAMT pointer (wins on collision)

Since: Phase P1

defn

hamt/hash-str

(hamt/hash-str [str :cstr] :int)

compute an xxHash64 of a NUL-terminated C string.

strNUL-terminated C string to hash

Since: Phase P1

defn

hamt/hash-ptr

(hamt/hash-ptr :int)

hash a pointer value directly (identity hash).

ptrpointer whose address is used as the hash input

Since: Phase P1

defn

hamt/iter-init

(hamt/iter-init [iter :ptr<void> m :ptr<void>] :void)

initialize a stack-allocated iterator over a HAMT.

iterpre-allocated buffer of at least 64 bytes
mHAMT pointer to iterate over

Since: Phase P1

defn

hamt/iter-free

(hamt/iter-free [iter :ptr<void>] :void)

release any resources held by an iterator.

iteriterator buffer previously passed to hamt/iter-init

Since: Phase P1

defn

hamt/iter-next

(hamt/iter-next [iter :ptr<void> hash-out :ptr<void> key-out :ptr<void> val-out :ptr<void>] :bool)

advance an iterator and write the next entry into out-pointers.

iteriterator buffer
hash-outpointer that receives the key hash
key-outpointer that receives the key pointer
val-outpointer that receives the value pointer

Since: Phase P1

defn

hamt/map

(hamt/map [m :ptr<void> fn :ptr<void> ctx :ptr<void>] :ptr<void>)

return a new HAMT with each value replaced by fn(val, ctx).

msource HAMT pointer
fnC function pointer (val :ptr, ctx :ptr) -> :ptr
ctxcaller-supplied context passed to fn

Since: Phase P1

defn

hamt/filter

(hamt/filter [m :ptr<void> fn :ptr<void> ctx :ptr<void>] :ptr<void>)

return a new HAMT keeping only entries where fn(key, val, ctx) is true.

msource HAMT pointer
fnC predicate pointer (key :ptr, val :ptr, ctx :ptr) -> bool
ctxcaller-supplied context passed to fn

Since: Phase P1

defn

hamt/reduce

(hamt/reduce [m :ptr<void> fn :ptr<void> init :ptr<void> ctx :ptr<void>] :ptr<void>)

fold all entries into an accumulator using fn(acc, key, val, ctx).

msource HAMT pointer
fnC function pointer (acc :ptr, key :ptr, val :ptr, ctx :ptr) -> :ptr
initinitial accumulator pointer
ctxcaller-supplied context passed to fn

Since: Phase P1

defn

hamt/merge-with

(hamt/merge-with [a :ptr<void> b :ptr<void> fn :ptr<void> ctx :ptr<void>] :ptr<void>)

merge two HAMTs, resolving key conflicts with fn(val_a, val_b, ctx).

afirst HAMT pointer
bsecond HAMT pointer
fnC function pointer (val_a :ptr, val_b :ptr, ctx :ptr) -> :ptr
ctxcaller-supplied context passed to fn

Since: Phase P1

defn

hamt/show

(hamt/show [m :ptr<void>] :cstr)

return a debug string "{k->v, ...}" for the HAMT; caller must free.

mHAMT pointer

Since: Phase P1

defn

hamt/dump

(hamt/dump [m :ptr<void>] :void)

write the HAMT structure in DOT format to stderr for debugging.

mHAMT pointer to dump

Since: Phase P1

defn

hamt/transient

(hamt/transient [m :ptr<void>] :ptr<void>)

fork a mutable transient from an immutable HAMT.

mimmutable HAMT pointer to fork from

Since: Phase P1

defn

hamt/transient-set!

(hamt/transient-set! [t :ptr<void> hash :int key :ptr<void> val :ptr<void>] :void)

mutate a transient by inserting or updating a key in place.

ttransient HAMT pointer
hash64-bit hash of the key
keykey pointer
valvalue pointer

Since: Phase P1

defn

hamt/transient-del!

(hamt/transient-del! [t :ptr<void> hash :int key :ptr<void>] :void)

mutate a transient by deleting a key in place.

ttransient HAMT pointer
hash64-bit hash of the key
keykey pointer

Since: Phase P1

defn

hamt/persistent!

(hamt/persistent! [t :ptr<void>] :ptr<void>)

seal a transient into an immutable HAMT.

ttransient HAMT pointer (must not be used after this call)

Since: Phase P1

Internal definitions