37 find_length(
const void *key,
38 unsigned (*do_hash)(
const void *,
unsigned,
unsigned))
41 return strlen((
const char *)key);
43 return sizeof(unsigned);
66 log_error (
"%s(%d): new_hash_table called with null pointer.",
68 #if defined (POINTER_DEBUG) 74 log_error (
"%s(%d): non-null target for new_hash_table.",
76 #if defined (POINTER_DEBUG) 91 (extra *
sizeof(
struct hash_bucket *)), file, line);
106 #if defined (DEBUG_MEMORY_LEAKAGE) || \ 107 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) 111 for (i = 0; i < ptr -> hash_count; i++) {
112 for (hbc = ptr -> buckets [i]; hbc; hbc = hbn) {
114 if (ptr -> dereferencer && hbc ->
value)
115 (*ptr -> dereferencer) (&hbc ->
value,
MDL);
117 for (hbc = ptr -> buckets [i]; hbc; hbc = hbn) {
131 #if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) 140 for (c = free_hash_buckets; c; c = c ->
next) {
141 for (n = hash_bucket_hunks; n; n = n ->
next) {
142 if (c > n && c < n + 127) {
154 for (c = hash_bucket_hunks; c; c = n) {
156 if (c ->
len != 126) {
157 log_info (
"hashbucket %lx hash_buckets %d free %u",
158 (
unsigned long)c, 127, c ->
len);
171 if (!free_hash_buckets) {
176 # if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) 177 rval ->
next = hash_bucket_hunks;
178 hash_bucket_hunks = rval;
179 hash_bucket_hunks ->
len = 0;
183 for (; i < 127; i++) {
185 free_hash_buckets = rval;
190 free_hash_buckets = rval ->
next;
199 #if defined (DEBUG_MALLOC_POOL) 202 for (hp = free_hash_buckets; hp; hp = hp ->
next) {
210 free_hash_buckets = ptr;
217 unsigned (*hasher)(
const void *,
unsigned,
unsigned),
218 const char *file,
int line)
226 memset ((*rp)->buckets, 0, hsize *
sizeof(
struct hash_bucket *));
228 (*rp)->referencer = referencer;
229 (*rp)->dereferencer = dereferencer;
230 (*rp)->do_hash = hasher;
243 register unsigned accum = 0;
244 register const unsigned char *s =
name;
255 accum = (accum << 1) + c;
258 while (accum > 65535) {
259 accum = (accum & 65535) + (accum >> 16);
269 register unsigned accum = 0;
270 register const unsigned char *s = (
const unsigned char *)name;
275 accum = (accum << 1) + *s++;
278 while (accum > 65535) {
279 accum = (accum & 65535) + (accum >> 16);
293 register unsigned accum = 0;
294 register const unsigned char *s = (
const unsigned char *)name;
295 const unsigned char *end = s +
len;
327 register unsigned number = *((
const unsigned *)key);
329 return number % size;
337 memcpy(&number, key, 4);
339 number = ntohl(number);
341 return number % size;
347 static unsigned char retbuf[
sizeof(
"Contents/Size (%): " 348 "2147483647/2147483647 " 350 "Min/max: 2147483647/2147483647")];
351 unsigned curlen, pct, contents=0, minlen=UINT_MAX, maxlen=0;
356 return (
unsigned char *)
"No table.";
359 return (
unsigned char *)
"Invalid hash table.";
378 if (contents >= (UINT_MAX / 100))
379 pct = contents / ((table->
hash_count / 100) + 1);
383 if (contents > 2147483647 ||
386 minlen > 2147483647 ||
388 return (
unsigned char *)
"Report out of range for display.";
390 sprintf((
char *)retbuf,
391 "Contents/Size (%%): %u/%u (%u%%). Min/max: %u/%u",
392 contents, table->
hash_count, pct, minlen, maxlen);
413 len = find_length(key, table->
do_hash);
419 log_error (
"Can't add entry to hash table: no memory.");
423 if (table -> referencer) {
425 (*(table -> referencer)) (foo, pointer,
file,
line);
427 bp ->
value = pointer;
428 bp ->
next = table -> buckets [hashno];
430 table -> buckets [hashno] = bp;
448 len = find_length(key, table->
do_hash);
454 for (bp = table -> buckets [hashno]; bp; bp = bp ->
next) {
456 !strcmp ((
const char *)bp->
name, key)) ||
458 !(table -> cmp)(bp->
name, key, len))) {
462 table -> buckets [hashno] = bp ->
next;
464 if (bp ->
value && table -> dereferencer) {
466 (*(table -> dereferencer)) (foo,
file,
line);
489 len = find_length(key, table->
do_hash);
492 log_fatal(
"Internal inconsistency: storage value has not been " 493 "initialized to zero (from %s:%d).", file, line);
498 for (bp = table -> buckets [hashno]; bp; bp = bp ->
next) {
501 if (table -> referencer)
502 (*table -> referencer) (vp, bp ->
value,
521 for (i = 0; i < table -> hash_count; i++) {
522 bp = table -> buckets [i];
535 int casecmp (
const void *v1,
const void *v2,
size_t len)
538 const unsigned char *s = v1;
539 const unsigned char *t = v2;
541 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)
struct hash_bucket * next
void * dmalloc(unsigned, const char *, int)
struct hash_bucket * free_hash_buckets
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
struct hash_bucket * new_hash_bucket(char *file, int line) const
int log_error(const char *,...) __attribute__((__format__(__printf__
unsigned do_id_hash(const void *name, unsigned len, unsigned size)
unsigned(* do_hash)(const void *, unsigned, unsigned)
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int new_hash_table(struct hash_table **tp, unsigned count, const char *file, int line)
int casecmp(const void *v1, const void *v2, size_t len)
unsigned do_string_hash(const void *name, unsigned len, unsigned size)
void free_hash_bucket(struct hash_bucket *ptr, 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 add_hash(struct hash_table *table, const void *key, unsigned len, hashed_object_t *pointer, const char *file, int line)
int(* hash_dereference)(hashed_object_t **, const char *, int)
void dfree(void *, const char *, int)
const unsigned char * name
isc_result_t(* hash_foreach_func)(const void *, unsigned, void *)
int int log_info(const char *,...) __attribute__((__format__(__printf__
struct hash_bucket * buckets[1]
void free_hash_table(struct hash_table **tp, const char *file, int line)
#define DEFAULT_HASH_SIZE
void delete_hash_entry(struct hash_table *table, const void *key, unsigned len, const char *file, int line)
unsigned do_ip4_hash(const void *key, unsigned len, unsigned size)
unsigned do_case_hash(const void *name, unsigned len, unsigned size)
unsigned do_number_hash(const void *key, unsigned len, unsigned size)
void relinquish_hash_bucket_hunks(void)
unsigned char * hash_report(struct hash_table *table)
int hash_foreach(struct hash_table *table, hash_foreach_func func)
int(* hash_reference)(hashed_object_t **, hashed_object_t *, const char *, int)