38 find_length(
const void *key,
39 unsigned (*do_hash)(
const void *,
unsigned,
unsigned))
42 return strlen((
const char *)key);
44 return sizeof(unsigned);
67 log_error (
"%s(%d): new_hash_table called with null pointer.",
69 #if defined (POINTER_DEBUG) 75 log_error (
"%s(%d): non-null target for new_hash_table.",
77 #if defined (POINTER_DEBUG) 107 #if defined (DEBUG_MEMORY_LEAKAGE) || \ 108 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) 112 for (i = 0; ptr != NULL && i < ptr -> hash_count; i++) {
113 for (hbc = ptr -> buckets [i]; hbc; hbc = hbn) {
115 if (ptr -> dereferencer && hbc ->
value)
116 (*ptr -> dereferencer) (&hbc ->
value,
MDL);
118 for (hbc = ptr -> buckets [i]; hbc; hbc = hbn) {
132 #if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) 142 for (n = hash_bucket_hunks; n; n = n ->
next) {
143 if (c > n && c < n + 127) {
155 for (c = hash_bucket_hunks; c; c = n) {
157 if (c ->
len != 126) {
158 log_info (
"hashbucket %lx hash_buckets %d free %u",
159 (
unsigned long)c, 127, c ->
len);
177 # if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) 178 rval ->
next = hash_bucket_hunks;
179 hash_bucket_hunks = rval;
180 hash_bucket_hunks ->
len = 0;
184 for (; i < 127; i++) {
200 #if defined (DEBUG_MALLOC_POOL) 218 unsigned (*hasher)(
const void *,
unsigned,
unsigned),
227 memset ((*rp)->buckets, 0, hsize *
sizeof(
struct hash_bucket *));
229 (*rp)->referencer = referencer;
230 (*rp)->dereferencer = dereferencer;
231 (*rp)->do_hash = hasher;
244 register unsigned accum = 0;
245 register const unsigned char *s =
name;
256 accum = (accum << 1) + c;
259 while (accum > 65535) {
260 accum = (accum & 65535) + (accum >> 16);
270 register unsigned accum = 0;
271 register const unsigned char *s = (
const unsigned char *)
name;
276 accum = (accum << 1) + *s++;
279 while (accum > 65535) {
280 accum = (accum & 65535) + (accum >> 16);
294 register unsigned accum = 0;
295 register const unsigned char *s = (
const unsigned char *)
name;
296 const unsigned char *end = s +
len;
328 register unsigned number = *((
const unsigned *)key);
330 return number % size;
338 memcpy(&number, key, 4);
340 number = ntohl(number);
342 return number % size;
348 static unsigned char retbuf[
sizeof(
"Contents/Size (%): " 349 "2147483647/2147483647 " 351 "Min/max: 2147483647/2147483647")];
352 unsigned curlen, pct, contents=0, minlen=UINT_MAX, maxlen=0;
357 return (
unsigned char *)
"No table.";
360 return (
unsigned char *)
"Invalid hash table.";
379 if (contents >= (UINT_MAX / 100))
380 pct = contents / ((table->
hash_count / 100) + 1);
384 if (contents > 2147483647 ||
387 minlen > 2147483647 ||
389 return (
unsigned char *)
"Report out of range for display.";
391 sprintf((
char *)retbuf,
392 "Contents/Size (%%): %u/%u (%u%%). Min/max: %u/%u",
393 contents, table->
hash_count, pct, minlen, maxlen);
420 log_error (
"Can't add entry to hash table: no memory.");
424 if (table -> referencer) {
426 (*(table -> referencer)) (foo, pointer,
file,
line);
428 bp ->
value = pointer;
429 bp ->
next = table -> buckets [hashno];
431 table -> buckets [hashno] = bp;
455 for (bp = table -> buckets [hashno]; bp; bp = bp ->
next) {
457 !strcmp ((
const char *)bp->
name, key)) ||
459 !(table -> cmp)(bp->
name, key,
len))) {
463 table -> buckets [hashno] = bp ->
next;
465 if (bp ->
value && table -> dereferencer) {
467 (*(table -> dereferencer)) (foo,
file,
line);
493 log_fatal(
"Internal inconsistency: storage value has not been " 494 "initialized to zero (from %s:%d).",
file,
line);
499 for (bp = table -> buckets [hashno]; bp; bp = bp ->
next) {
502 if (table -> referencer)
503 (*table -> referencer) (vp, bp ->
value,
522 for (i = 0; i < table -> hash_count; i++) {
523 bp = table -> buckets [i];
539 const unsigned char *s = v1;
540 const unsigned char *t = v2;
542 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
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 * dmalloc(size_t, const char *, int)
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)