38 int (*h)(
const void *key);
39 int (*match)(
const void *key1,
const void *key2);
40 void (*destroy)(
void *data);
49 CHtbl CHTBLinit(
int buckets,
int (*h)(
const void *key),
int (*match)(
const void *key1,
const void *key2),
void (*destroy)(
void *data))
54 if ((htbl = (
CHtbl)malloc(
sizeof(
struct CHtbl_)))==NULL)
57 if ((htbl->table = (
Slist *)malloc(buckets *
sizeof(
Slist))) == NULL)
60 htbl->buckets = buckets;
62 for (i = 0; i < htbl->buckets; i++)
64 if ((htbl->table[i] =
SLISTinit(destroy)) == NULL)
71 htbl->destroy = destroy;
81 for (i = 0; i < htbl->buckets; ++i)
101 bucket = htbl->h(data) % htbl->buckets;
103 if ((retval =
SLISTinsnext(htbl->table[bucket], NULL, data)) == 0)
114 bucket = htbl->h(*data) % htbl->buckets;
129 bucket = htbl->h(*data) % htbl->buckets;
144 for (i = 0; i < htbl->buckets; ++i)
146 printf(
"\nBucket #%03d: ", i);