24 #define BITS_IN_int ( sizeof(int) * CHAR_BIT )
25 #define THREE_QUARTERS ((int) ((BITS_IN_int * 3) / 4))
26 #define ONE_EIGHTH ((int) (BITS_IN_int / 8))
27 #define HIGH_BITS ( ~((unsigned int)(~0) >> ONE_EIGHTH ))
43 char *datum = (
char *)key;
44 unsigned int hash_value, i;
48 for (hash_value = 0; *datum; ++datum) {
49 hash_value = (hash_value <<
ONE_EIGHTH) + *datum;
56 static int string_compare(
void* a,
void* b)
58 return (strcmp( (
char*)a, (
char*)b ) == 0);
73 icl_hash_create(
int nbuckets,
unsigned int (*hash_function)(
void*),
int (*hash_key_compare)(
void*,
void*) )
111 unsigned int hash_val;
113 if(!ht || !key)
return NULL;
117 for (curr=ht->
buckets[hash_val]; curr != NULL; curr=curr->
next)
138 unsigned int hash_val;
140 if(!ht || !key)
return NULL;
144 for (curr=ht->
buckets[hash_val]; curr != NULL; curr=curr->
next)
150 assert(curr != NULL);
151 if(!curr)
return NULL;
178 unsigned int hash_val;
180 if(!ht || !key)
return NULL;
185 for (prev=NULL,curr=ht->
buckets[hash_val]; curr != NULL; prev=curr, curr=curr->
next)
188 if (olddata != NULL) {
189 *olddata = curr->
data;
202 if(curr == NULL)
return NULL;
211 if(olddata!=NULL && *olddata!=NULL)
230 unsigned int hash_val;
232 if(!ht || !key)
return -1;
236 for (curr=ht->
buckets[hash_val]; curr != NULL; ) {
243 if (*free_key && curr->
key) (*free_key)(curr->
key);
244 if (*free_data && curr->
data) (*free_data)(curr->
data);
274 for (curr=bucket; curr!=NULL; ) {
276 if (*free_key && curr->
key) (*free_key)(curr->
key);
277 if (*free_data && curr->
data) (*free_data)(curr->
data);
309 for(curr=bucket; curr!=NULL; ) {
311 fprintf(stream,
"icl_hash_dump: %s: %p\n", (
char *)curr->
key, curr->
data);