There is a set of builtins that are useful for using Hashtables. A hashtable is not a basic type, but an abstract type. It can then only be manipulated using the following builtins :
$hnew(size): create a new hashtable having initialy
$hadd(h,k,v): add the value
kto the hashtable. Please note that
kcan be any Neko value, even recursive.
$hset(h,k,v,cmp): set the value of the key
v. The previous binding is replaced if the
cmpfunction between keys returns 0. If
null, the default comparison function is used.
$hmem(h,k,cmp): returns true if a value exists for key
kin the Hashtable.
$hget(h,k,cmp): returns the first value bound to key
nullif not found.
$hremove(h,k,cmp): removes the first binding of
k, and returns a boolean indicating the success.
$hresize(h,size): resize the hashtable. Please note that the size is usually automaticaly handled.
$hsize(h): returns the size of the hashtable.
$hcount(h): returns the number of bindings in the hashtable.
f(k,v)for each binding found in the hashtable.
The hashtable stores the (key, values) couples in one chained list per slot. Adding a new binding with the same key will mask the previous one. The hash function used internally is
$hkey(k), which will return a positive Neko integer for any Neko value. The hash function cannot be overridden, but the comparison function between keys can be overridden where it is used.
You can, of course, write your own hashtable implementation using Neko data structures, but using the standard builtin hashtable is better for languages interoperability.