hash.h revision 7c424aa51c956c628e3512055841aa2f9eef4833
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen/* Returns hash code. */
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainentypedef unsigned int hash_callback_t(const void *p);
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainen/* Returns 0 if the pointers are equal. */
48acc31adebfdd4e4945ee76e1f5259e4b1b6fffTimo Sirainentypedef int hash_cmp_callback_t(const void *p1, const void *p2);
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainentypedef void hash_foreach_callback_t(void *key, void *value, void *context);
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen/* Create a new hash table. If initial_size is 0, the default value is used.
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen If hash_cb or key_compare_cb is NULL, direct hashing/comparing is used.
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen table_pool is used to allocate/free large hash tables, node_pool is used
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen for smaller allocations and can also be alloconly pool. The pools must not
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen be free'd before hash_destroy() is called. */
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainenhash_create(pool_t table_pool, pool_t node_pool, size_t initial_size,
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen hash_callback_t *hash_cb, hash_cmp_callback_t *key_compare_cb);
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen/* Remove all nodes from hash table. If free_collisions is TRUE, the
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen memory allocated from node_pool is freed, or discarded with
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen alloconly pools. */
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainenvoid hash_clear(struct hash_table *table, int free_collisions);
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainenvoid *hash_lookup(struct hash_table *table, const void *key);
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainenint hash_lookup_full(struct hash_table *table, const void *lookup_key,
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen/* Insert/update node in hash table. The difference is that hash_insert()
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen replaces the key in table to given one, while hash_update() doesnt. */
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainenvoid hash_insert(struct hash_table *table, void *key, void *value);
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainenvoid hash_update(struct hash_table *table, void *key, void *value);
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainenvoid hash_remove(struct hash_table *table, const void *key);
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen/* Calls the given function for each node in hash table. You may safely
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen call hash_*() functions inside your function, but if you add any
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen new nodes, they may or may not be called for in this foreach loop. */
4082d5b171d1c3a00ba705093d62b8afc9cf17aeTimo Sirainen hash_foreach_callback_t *callback, void *context);
d06d6667bac64aabe1efb216af56ca45108d63b0Timo Sirainen/* Stop the active hash_foreach() loop */
d06d6667bac64aabe1efb216af56ca45108d63b0Timo Sirainen/* Hash table isn't resized, and removed nodes aren't removed from
d06d6667bac64aabe1efb216af56ca45108d63b0Timo Sirainen the list while hash table is freezed. Supports nesting. */
86bde2c1838d1ce967fa2b394bb952004a4adcb7Timo Sirainen/* hash function for strings */
d06d6667bac64aabe1efb216af56ca45108d63b0Timo Sirainenunsigned int str_hash(const void *p);
c8bac7666cdc780a3390110e420350fffb62b909Timo Sirainenunsigned int strcase_hash(const void *p);