32 int (*h1)(
const void *key);
33 int (*h2)(
const void *key);
34 int (*match)(
const void *key1,
const void *key2);
35 void (*destroy)(
void *data);
46 OHtbl OHTBLinit(
int positions,
int (*h1)(
const void *key),
int (*h2)(
const void *key),
47 int (*match)(
const void *key1,
const void *key2),
void (*destroy)(
void *data))
53 if ((htbl = malloc(
sizeof(
struct OHtbl_))) == NULL)
57 if ((htbl->table = (
void **)malloc(positions *
sizeof(
void *))) == NULL)
61 htbl->positions = positions;
63 for (i = 0; i < htbl->positions; i++)
64 htbl->table[i] = NULL;
67 htbl->vacated = &vacated;
73 htbl->destroy = destroy;
85 if (htbl->destroy != NULL)
88 for (i = 0; i < htbl->positions; i++)
90 if (htbl->table[i] != NULL && htbl->table[i] != htbl->vacated)
91 htbl->destroy(htbl->table[i]);
108 if (htbl->size == htbl->positions)
118 for (i = 0; i < htbl->positions; i++)
120 position = (htbl->h1(data) + (i * htbl->h2(data))) % htbl->positions;
122 if (htbl->table[position] == NULL || htbl->table[position] == htbl->vacated)
125 htbl->table[position] = (
void *)data;
140 for (i = 0; i < htbl->positions; i++)
142 position = (htbl->h1(*data) + (i * htbl->h2(*data))) % htbl->positions;
144 if (htbl->table[position] == NULL)
149 else if (htbl->table[position] == htbl->vacated)
154 else if (htbl->match(htbl->table[position], *data))
157 *data = htbl->table[position];
158 htbl->table[position] = htbl->vacated;
173 for (i = 0; i < htbl->positions; i++)
175 position = (htbl->h1(*data) + (i * htbl->h2(*data))) % htbl->positions;
177 if (htbl->table[position] == NULL)
182 else if (htbl->match(htbl->table[position], *data))
185 *data = htbl->table[position];
203 for (i=0; i<htbl->positions; i++)
205 if (htbl->table[i] == NULL)
207 else if (htbl->table[i] == htbl->vacated)
210 callback(htbl->table[i]);