17 #define HASH_LIMIT 0.5 39 i=(i<<3)+(*
key++ -
'0');
63 for (i=0; i<old_size; i++) {
64 old_hash=old_bucket[i];
67 old_hash=old_hash->
next;
100 while (tptr->
size<buckets) {
126 for (node=tptr->
bucket[h]; node!=NULL; node=node->
next) {
127 if (!strcmp(node->
key,
key))
184 for (node=tptr->
bucket[h]; node; node=node->
next) {
185 if (!strcmp(node->
key,
key))
194 if (node==tptr->
bucket[h])
199 if (last->
next==node)
222 for (i=0; i<tptr->
size; i++) {
224 while (node != NULL) {
232 if (tptr->
bucket != NULL) {
249 for (i=0; i<tptr->
size; i++) {
250 for (node=tptr->
bucket[i], j=0; node!=NULL; node=node->
next, j++);
252 alos+=((j*(j+1))>>1);
265 static char buf[1024];
267 sprintf(buf,
"%u slots, %u entries, and %1.2f ALOS",
int mask
used to select bits for hashing
#define HASH_FAIL
Return code when a hash key is not find, or there's no collision upon insertion.
void rt_hash_init(rt_hash_t *tptr, int buckets)
void rt_hash_destroy(rt_hash_t *tptr)
struct hash_node_t ** bucket
array of hash nodes
int entries
number of entries in table
struct hash_node_t * next
int rt_hash_delete(rt_hash_t *tptr, const char *key)
struct hash_node_t hash_node_t
static void rebuild_table(rt_hash_t *tptr)
static float alos(rt_hash_t *tptr)
int downshift
shift cound, used in hash function
int rt_hash_insert(rt_hash_t *tptr, const char *key, int data)
int size
size of the array
char * rt_hash_stats(rt_hash_t *tptr)
int rt_hash_lookup(rt_hash_t *tptr, const char *key)
static int hash(rt_hash_t *tptr, const char *key)