2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-30 05:47:45 +00:00

- Add reference and dereference functions to hash, so that reference-counted

objects can be cleanly hashed.
This commit is contained in:
Ted Lemon 2000-03-06 23:15:16 +00:00
parent 5b6b5c33b6
commit 0cae26a712

View File

@ -22,20 +22,23 @@
#ifndef lint #ifndef lint
static char copyright[] = static char copyright[] =
"$Id: hash.c,v 1.16 2000/01/26 14:55:34 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; "$Id: hash.c,v 1.17 2000/03/06 23:15:16 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#include "dhcpd.h" #include "dhcpd.h"
static INLINE int do_hash PROTO ((const unsigned char *, unsigned, unsigned)); static INLINE int do_hash PROTO ((const unsigned char *, unsigned, unsigned));
struct hash_table *new_hash () struct hash_table *new_hash (hash_reference referencer,
hash_dereference dereferencer)
{ {
struct hash_table *rv = new_hash_table (DEFAULT_HASH_SIZE, MDL); struct hash_table *rv = new_hash_table (DEFAULT_HASH_SIZE, MDL);
if (!rv) if (!rv)
return rv; return rv;
memset (&rv -> buckets [0], 0, memset (&rv -> buckets [0], 0,
DEFAULT_HASH_SIZE * sizeof (struct hash_bucket *)); DEFAULT_HASH_SIZE * sizeof (struct hash_bucket *));
rv -> referencer = referencer;
rv -> dereferencer = dereferencer;
return rv; return rv;
} }
@ -62,10 +65,11 @@ void add_hash (table, name, len, pointer)
struct hash_table *table; struct hash_table *table;
unsigned len; unsigned len;
const unsigned char *name; const unsigned char *name;
unsigned char *pointer; void *pointer;
{ {
int hashno; int hashno;
struct hash_bucket *bp; struct hash_bucket *bp;
void *foo;
if (!table) if (!table)
return; return;
@ -81,7 +85,11 @@ void add_hash (table, name, len, pointer)
return; return;
} }
bp -> name = name; bp -> name = name;
bp -> value = pointer; if (table -> referencer) {
foo = &bp -> value;
(*(table -> referencer)) (foo, pointer, MDL);
} else
bp -> value = pointer;
bp -> next = table -> buckets [hashno]; bp -> next = table -> buckets [hashno];
bp -> len = len; bp -> len = len;
table -> buckets [hashno] = bp; table -> buckets [hashno] = bp;
@ -94,6 +102,7 @@ void delete_hash_entry (table, name, len)
{ {
int hashno; int hashno;
struct hash_bucket *bp, *pbp = (struct hash_bucket *)0; struct hash_bucket *bp, *pbp = (struct hash_bucket *)0;
void *foo;
if (!table) if (!table)
return; return;
@ -115,6 +124,10 @@ void delete_hash_entry (table, name, len)
} else { } else {
table -> buckets [hashno] = bp -> next; table -> buckets [hashno] = bp -> next;
} }
if (table -> dereferencer) {
foo = &bp -> value;
(*(table -> dereferencer)) (foo, MDL);
}
free_hash_bucket (bp, MDL); free_hash_bucket (bp, MDL);
break; break;
} }
@ -122,7 +135,7 @@ void delete_hash_entry (table, name, len)
} }
} }
unsigned char *hash_lookup (table, name, len) void *hash_lookup (table, name, len)
struct hash_table *table; struct hash_table *table;
const unsigned char *name; const unsigned char *name;
unsigned len; unsigned len;