hash.h revision 00bd7d0e21ffa84965fd6aa0ccbc54aab7fad77c
#ifndef HASH_H
#define HASH_H
struct hash_table;
#ifdef HAVE_TYPEOF
#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.
WARNING: If you p_clear() the node_pool, the free_collisions must be TRUE. */
(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);
#ifndef __cplusplus
(void *)((const char *)(lookup_key) + \
(void *)((orig_key_r) + \
COMPILE_ERROR_IF_TRUE(sizeof(*(orig_key_r)) != sizeof(void *))), \
(void *)((value_r) + \
COMPILE_ERROR_IF_TRUE(sizeof(*(value_r)) != sizeof(void *))))
#else
/* C++ requires (void **) casting, but that's not possible with strict
aliasing, so .. we'll just disable the type checks */
#endif
/* Suppose to insert a new key-value node to the hash table.
If the key already exists, assert-crash. */
/* If the key doesn't exists, do the exact same as hash_table_insert()
If the key already exists, preserve the original key and update only the value.*/
(const void *)((const char *)(key) + COMPILE_ERROR_IF_TYPES2_NOT_COMPATIBLE((table)._const_key, (table)._key, key)))
STMT_START { \
i_panic("key not found from hash"); \
} STMT_END
#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) \
#ifndef __cplusplus
(void *)((key_r) + \
COMPILE_ERROR_IF_TRUE(sizeof(*(key_r)) != sizeof(void *)) + \
COMPILE_ERROR_IF_TRUE(sizeof(*(value_r)) != sizeof(void *))), \
#else
/* C++ requires (void **) casting, but that's not possible with strict
aliasing, so .. we'll just disable the type checks */
#endif
/* 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;
/* fast hash function which uppercases a-z. Does not work well
it works by dropping 0x20. */
unsigned int strfastcase_hash(const char *p) ATTR_PURE;
/* a generic hash for a given memory block */
#endif