hash.h revision 60626b57f0fa514c9dd99880713c5268f27b1b1d
#ifndef HASH_H
#define HASH_H
struct hash_table;
#ifdef __GNUC__
#else
# define HASH_VALUE_CAST(table)
#endif
/* Returns hash code. */
typedef unsigned int hash_callback_t(const void *p);
/* Returns 0 if the pointers are equal. */
/* Create a new hash table. If initial_size is 0, the default value is used.
for smaller allocations and can also be alloconly pool. The pools must not
be free'd before hash_table_destroy() is called. */
unsigned int initial_size,
#if defined (__GNUC__) && !defined(__cplusplus)
({(void)COMPILE_ERROR_IF_TRUE( \
(void)COMPILE_ERROR_IF_TRUE( \
(void)COMPILE_ERROR_IF_TRUE( \
(hash_callback_t *)hash_cb, \
(hash_cmp_callback_t *)key_cmp_cb);})
#else
(hash_callback_t *)hash_cb, \
#endif
/* Create hash table where comparisons are done directly with the pointers. */
unsigned int initial_size);
#if defined (__GNUC__) && !defined(__cplusplus)
({(void)COMPILE_ERROR_IF_TRUE( \
#else
#endif
#define hash_table_is_created(table) \
#define hash_table_destroy(table) \
/* Remove all nodes from hash table. If free_collisions is TRUE, the
memory allocated from node_pool is freed, or discarded with
alloconly pools. */
(const void *)((const char *)(key) + COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE((table)._key, (table)._const_key, key)))
const void *lookup_key,
void **orig_key_r, void **value_r);
(void *)((const char *)(lookup_key) + COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE((table)._const_key, (table)._key, lookup_key)), \
(void **)(void *)((orig_key_r) + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE((table)._keyp, orig_key_r) + \
COMPILE_ERROR_IF_TRUE(sizeof(*orig_key_r) != sizeof(void *))), \
COMPILE_ERROR_IF_TRUE(sizeof(*value_r) != sizeof(void *))))
replaces the key in table to given one, while hash_table_update() doesnt. */
(const void *)((const char *)(key) + COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE((table)._const_key, (table)._key, key)))
#define hash_table_count(table) \
/* Iterates through all nodes in hash table. You may safely call hash_table_*()
functions while iterating, but if you add any new nodes, they may or may
not be called for in this iteration. */
#define hash_table_iterate_init(table) \
COMPILE_ERROR_IF_TRUE(sizeof(*key_r) != sizeof(void *)) + \
COMPILE_ERROR_IF_TRUE(sizeof(*value_r) != sizeof(void *))), \
/* Hash table isn't resized, and removed nodes aren't removed from
the list while hash table is freezed. Supports nesting. */
#define hash_table_freeze(table) \
#define hash_table_thaw(table) \
/* Copy all nodes from one hash table to another */
/* hash function for strings */
unsigned int strcase_hash(const char *p) ATTR_PURE;
/* a generic hash for a given memory block */
#endif