34 return (
unsigned long)((((ptrdiff_t)k *
LH_PRIME) >> 4) & ULONG_MAX);
47 while( *data!=0 ) h = h*129 + (
unsigned int)(*data++) +
LH_PRIME;
54 return (strcmp((
char*)k1, (
char*)k2) == 0);
65 t = calloc(1,
sizeof(
struct lh_table));
66 if(!t)
lh_abort(
"lh_table_new: calloc failed\n");
114 for(c = t->
head; c != NULL; c = c->
next) {
137 if(++n == (
size_t) t->
size) n = 0;
144 if(t->
head == NULL) {
160 unsigned long h = t->
hash_fn(k);
161 unsigned long n = h % t->
size;
168 if(++n == (
size_t) t->
size) n = 0;
184 ptrdiff_t n = (ptrdiff_t)(e - t->
table);
187 if(n < 0) {
return -2; }
int( lh_equal_fn)(void *k1, void *k2)
lh_entry_free_fn * free_fn
int lh_char_equal(void *k1, void *k2)
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
int lh_table_delete(struct lh_table *t, void *k)
void lh_abort(const char *msg,...)
unsigned long( lh_hash_fn)(void *k)
struct lh_table * lh_kptr_table_new(int size, char *name, lh_entry_free_fn *free_fn)
int lh_table_insert(struct lh_table *t, void *k, void *v)
struct lh_table * lh_table_new(int size, char *name, lh_entry_free_fn *free_fn, lh_hash_fn *hash_fn, lh_equal_fn *equal_fn)
void lh_table_free(struct lh_table *t)
struct lh_table * lh_kchar_table_new(int size, char *name, lh_entry_free_fn *free_fn)
void * lh_table_lookup(struct lh_table *t, void *k)
struct lh_entry * lh_table_lookup_entry(struct lh_table *t, void *k)
void lh_table_resize(struct lh_table *t, int new_size)
unsigned long lh_ptr_hash(void *k)
void( lh_entry_free_fn)(struct lh_entry *e)
unsigned long lh_char_hash(void *k)
int lh_ptr_equal(void *k1, void *k2)