2.4.2.1 Datatypes

typedef struct ZixHashImpl ZixHash

A hash table.

This is an open addressing hash table that stores pointers to arbitrary user data. Internally, everything is stored in a single flat array that is resized when necessary.

The single user-provided pointer that is stored in the table is called a “record”. A record contains a “key”, which is accessed via a user-provided function. This design supports storing large records (which may be expensive to allocate/construct) without requiring an entire record to search. Simple atomic values can be stored by providing a trivial identity function as a key function.

The table uses power of 2 sizes with a growth factor of 2, so that hash values can be folded into an array index using bitwise AND as a fast modulo. This means that only the necessary low bits of the hash value will be used, so the hash function must be well-balanced within this range. More or less any good modern hash algorithm will be fine, but beware, for example, hash functions that assume they are targeting a table with a prime size.

Since this doubles and halves in size, it may not be an optimal choice if memory reuse is a priority. A growth factor of 1.5 with fast range reduction may be a better choice there, at the cost of requiring 128-bit arithmetic on 64-bit platforms, and indexing operations being slightly more expensive.

typedef size_t ZixHashCode

A full hash code for a key which is not folded down to the table size.

typedef void ZixHashKey

The type of a key within a record.

typedef void ZixHashRecord

The type of a hash table record.

typedef void ZixHashSearchData

User data for key comparison function.