32 const unsigned char *s =
static_cast<const unsigned char *
>(data);
52 const char *key =
static_cast<const char *
>(data);
57#define HASH4a h = (h << 5) - h + *key++;
58#define HASH4b h = (h << 5) + h + *key++;
64 switch (len & (8 - 1)) {
114 hid->
size = (
unsigned int) hash_sz;
118 hid->
hash = hash_func;
152 if ((hid->
cmp) (k, walker->
key) == 0) {
177 if (
nullptr == hid->
next)
194 if (
nullptr == hid->
next)
228 if (hid->
next == hl) {
230 if (
nullptr == hid->
next)
246 if (bucket >= hid->
size)
258 while ((l =
hash_next(hid)) && i < hid->count) {
262 for (
int j = 0; j < i; ++j)
263 free_func(*(list + j));
299 for (
int i = 0; i < I; ++i) {
315 return (
const char *) hl->
key;
335 printf(
"creating hash table\n");
337 printf(
"hash_create error.\n");
340 printf(
"done creating hash table: %d\n", hid);
343 std::uniform_int_distribution<> dist(0,16);
345 while (fgets(buf,
BUFSIZ, stdin)) {
346 buf[strlen(buf) - 1] =
'\0';
347 printf(
"Inserting '%s' for item %p to hash table: %d\n",
349 hash_insert(hid,
xstrdup(buf), (
void *) 0x12345678);
351 strcpy(todelete, buf);
354 printf(
"walking hash table...\n");
356 printf(
"item %5d: key: '%s' item: %p\n", i++, walker->
key,
359 printf(
"done walking hash table...\n");
362 printf(
"deleting %s from %d\n", todelete, hid);
363 if (hash_delete(hid, todelete))
364 printf(
"hash_delete error\n");
366 printf(
"walking hash table...\n");
368 printf(
"item %5d: key: '%s' item: %p\n", i++, walker->
key,
371 printf(
"done walking hash table...\n");
373 printf(
"driver finished.\n");
void log(char *format,...)
unsigned int current_slot
A const & min(A const &lhs, A const &rhs)
hash_link * hash_lookup(hash_table *hid, const void *k)
void hashFreeMemory(hash_table *hid)
const char * hashKeyStr(const hash_link *hl)
hash_link * hash_next(hash_table *hid)
void hash_remove_link(hash_table *hid, hash_link *hl)
static void hash_next_bucket(hash_table *hid)
hash_table * hash_create(HASHCMP *cmp_func, int hash_sz, HASHHASH *hash_func)
hash_link * hash_get_bucket(hash_table *hid, unsigned int bucket)
unsigned int hash4(const void *data, unsigned int size)
void hashFreeItems(hash_table *hid, HASHFREE *free_func)
void hash_first(hash_table *hid)
void hash_join(hash_table *hid, hash_link *lnk)
void hash_last(hash_table *hid)
unsigned int hash_string(const void *data, unsigned int size)
int HASHCMP(const void *, const void *)
unsigned int HASHHASH(const void *, unsigned int)
#define DEFAULT_HASH_SIZE
#define LOCAL_ARRAY(type, name, size)
int main(int argc, char *argv[])
void * xcalloc(size_t n, size_t sz)