make_hashtable(hfn, eqp, @optional size)
Return a new hash table.
Hash tables represent sets of associations between arbitrary values. They serve essentially the same purpose as association lists
but are typically much faster when large numbers of associations are involved. Hash table literals are written by enclosing pairs of
associations in a #{}
, example – #{'name:"nemo", 'age:3}
. A hash table literal is internally constructed by calling make_equal_hashtable
.
The arguments hfn
and eqp
must be functions. If size
is provided, it must be a nonnegative
exact integer indicating approximately how many elements the hash table should initially hold.
Hash tables grow as needed, but when the hash table grows it generally must rehash all of the
existing elements. Providing a nonzero size can help limit the amount of rehashing that must
be done as the table is initially populated.
The new hash table computes hash values using hfn
and compare keys using eqp
,
neither of which should modify the hash table. Eqp
should compare two keys and return
false
only if the two keys should be distinguished. Hfn
should accept a key as an
argument and return a nonnegative exact integer value that is the same each time it is called
with arguments that eqp
does not distinguish.
let h = make_hashtable(string_hash, string_is_eq)
hashtable_set(h, "name", "mat")
hashtable_at(h, "name")
// "mat"