The
hashinit() function allocates and initializes space for a simple chaining hash table. The number of slots will be the least power of two not smaller than
chains. The customary choice for
chains is the maximum number of elements you intend to store divided by your intended load factor. The
LIST... or
TAILQ... macros of
queue(3) can be used to manipulate the chains; pass
HASH_LIST or
HASH_TAILQ as
htype to indicate which. Each slot will be initialized as the head of an empty chain of the proper type. Because different data structures from
queue(3) can define head structures of different sizes, the total size of the allocated table can vary with the choice of
htype.
If
waitok is true,
hashinit can wait until enough memory is available. Otherwise, it immediately fails if there is not enough memory is available.
A value will be stored into
*hashmask suitable for masking any computed hash, to obtain the index of a chain head in the allocated table.
The
hashdone() function deallocates the storage allocated by
hashinit() and pointed to by
hashtbl, given the same
htype and
hashmask that were passed to and returned from
hashinit(). If the table contains any nonempty chain when
hashdone() is called, the result is undefined.