36find_length(
const void *key,
37 unsigned (*do_hash)(
const void *,
unsigned,
unsigned))
40 return strlen((
const char *)key);
42 return sizeof(unsigned);
65 log_error (
"%s(%d): new_hash_table called with null pointer.",
67#if defined (POINTER_DEBUG)
73 log_error (
"%s(%d): non-null target for new_hash_table.",
75#if defined (POINTER_DEBUG)
105#if defined (DEBUG_MEMORY_LEAKAGE) || \
106 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
110 for (i = 0; ptr != NULL && i < ptr -> hash_count; i++) {
111 for (hbc = ptr -> buckets [i]; hbc; hbc = hbn) {
113 if (ptr -> dereferencer && hbc ->
value)
114 (*ptr -> dereferencer) (&hbc ->
value,
MDL);
116 for (hbc = ptr -> buckets [i]; hbc; hbc = hbn) {
130#if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
140 for (n = hash_bucket_hunks; n; n = n ->
next) {
141 if (c > n && c < n + 127) {
153 for (c = hash_bucket_hunks; c; c = n) {
155 if (c ->
len != 126) {
156 log_info (
"hashbucket %lx hash_buckets %d free %u",
157 (
unsigned long)c, 127, c ->
len);
175# if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
176 rval ->
next = hash_bucket_hunks;
177 hash_bucket_hunks = rval;
178 hash_bucket_hunks ->
len = 0;
182 for (; i < 127; i++) {
198#if defined (DEBUG_MALLOC_POOL)
216 unsigned (*hasher)(
const void *,
unsigned,
unsigned),
225 memset ((*rp)->buckets, 0, hsize *
sizeof(
struct hash_bucket *));
227 (*rp)->referencer = referencer;
228 (*rp)->dereferencer = dereferencer;
229 (*rp)->do_hash = hasher;
242 register unsigned accum = 0;
243 register const unsigned char *s =
name;
254 accum = (accum << 1) + c;
257 while (accum > 65535) {
258 accum = (accum & 65535) + (accum >> 16);
268 register unsigned accum = 0;
269 register const unsigned char *s = (
const unsigned char *)
name;
274 accum = (accum << 1) + *s++;
277 while (accum > 65535) {
278 accum = (accum & 65535) + (accum >> 16);
292 register unsigned accum = 0;
293 register const unsigned char *s = (
const unsigned char *)
name;
294 const unsigned char *end = s +
len;
326 register unsigned number = *((
const unsigned *)key);
328 return number % size;
336 memcpy(&number, key, 4);
338 number = ntohl(number);
340 return number % size;
346 static unsigned char retbuf[
sizeof(
"Contents/Size (%): "
347 "2147483647/2147483647 "
349 "Min/max: 2147483647/2147483647")];
350 unsigned curlen, pct, contents=0, minlen=UINT_MAX, maxlen=0;
355 return (
unsigned char *)
"No table.";
358 return (
unsigned char *)
"Invalid hash table.";
377 if (contents >= (UINT_MAX / 100))
378 pct = contents / ((table->
hash_count / 100) + 1);
382 if (contents > 2147483647 ||
385 minlen > 2147483647 ||
387 return (
unsigned char *)
"Report out of range for display.";
389 sprintf((
char *)retbuf,
390 "Contents/Size (%%): %u/%u (%u%%). Min/max: %u/%u",
391 contents, table->
hash_count, pct, minlen, maxlen);
418 log_error (
"Can't add entry to hash table: no memory.");
422 if (table -> referencer) {
424 (*(table -> referencer)) (foo, pointer,
file,
line);
426 bp ->
value = pointer;
427 bp ->
next = table -> buckets [hashno];
429 table -> buckets [hashno] = bp;
453 for (bp = table -> buckets [hashno]; bp; bp = bp ->
next) {
455 !strcmp ((
const char *)bp->
name, key)) ||
457 !(table -> cmp)(bp->
name, key,
len))) {
461 table -> buckets [hashno] = bp ->
next;
463 if (bp ->
value && table -> dereferencer) {
465 (*(table -> dereferencer)) (foo,
file,
line);
491 log_fatal(
"Internal inconsistency: storage value has not been "
492 "initialized to zero (from %s:%d).",
file,
line);
497 for (bp = table -> buckets [hashno]; bp; bp = bp ->
next) {
500 if (table -> referencer)
501 (*table -> referencer) (vp, bp ->
value,
520 for (i = 0; i < table -> hash_count; i++) {
521 bp = table -> buckets [i];
537 const unsigned char *s = v1;
538 const unsigned char *t = v2;
540 for (i = 0; i <
len; i++)
int new_hash(struct hash_table **rp, hash_reference referencer, hash_dereference dereferencer, unsigned hsize, unsigned(*hasher)(const void *, unsigned, unsigned), const char *file, int line)
unsigned do_case_hash(const void *name, unsigned len, unsigned size)
unsigned do_ip4_hash(const void *key, unsigned len, unsigned size)
void delete_hash_entry(struct hash_table *table, const void *key, unsigned len, const char *file, int line)
unsigned do_id_hash(const void *name, unsigned len, unsigned size)
int casecmp(const void *v1, const void *v2, size_t len)
void add_hash(struct hash_table *table, const void *key, unsigned len, hashed_object_t *pointer, const char *file, int line)
struct hash_bucket * new_hash_bucket(char *file, int line) const
unsigned do_number_hash(const void *key, unsigned len, unsigned size)
int hash_foreach(struct hash_table *table, hash_foreach_func func)
void free_hash_bucket(struct hash_bucket *ptr, const char *file, int line)
struct hash_bucket * free_hash_buckets
int new_hash_table(struct hash_table **tp, unsigned count, const char *file, int line)
int hash_lookup(hashed_object_t **vp, struct hash_table *table, const void *key, unsigned len, const char *file, int line)
void free_hash_table(struct hash_table **tp, const char *file, int line)
unsigned do_string_hash(const void *name, unsigned len, unsigned size)
unsigned char * hash_report(struct hash_table *table)
int casecmp(const void *s, const void *t, size_t len)
unsigned do_case_hash(const void *, unsigned, unsigned)
void relinquish_hash_bucket_hunks(void)
int(* hash_dereference)(hashed_object_t **, const char *, int)
isc_result_t(* hash_foreach_func)(const void *, unsigned, void *)
int new_hash_table(struct hash_table **, unsigned, const char *, int)
int(* hash_reference)(hashed_object_t **, hashed_object_t *, const char *, int)
unsigned do_string_hash(const void *, unsigned, unsigned)
unsigned do_ip4_hash(const void *, unsigned, unsigned)
unsigned do_number_hash(const void *, unsigned, unsigned)
#define DEFAULT_HASH_SIZE
void * dmalloc(size_t, const char *, int)
void dfree(void *, const char *, int)
int log_error(const char *,...) __attribute__((__format__(__printf__
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int int log_info(const char *,...) __attribute__((__format__(__printf__
struct hash_bucket * next
const unsigned char * name
unsigned(* do_hash)(const void *, unsigned, unsigned)
struct hash_bucket * buckets[1]