static void json_object_init(void) __attribute__ ((constructor));
static void json_object_init(void) {
MC_DEBUG("json_object_init: creating object table\n");
- json_object_table = lh_kptr_table_new(128, "json_object_table", NULL);
+ json_object_table = lh_kptr_table_new(128, NULL);
}
static void json_object_fini(void) __attribute__ ((destructor));
jso->_delete = &json_object_object_delete;
jso->_to_json_string = &json_object_object_to_json_string;
jso->o.c_object = lh_kchar_table_new(JSON_OBJECT_DEF_HASH_ENTRIES,
- NULL, &json_object_lh_entry_free);
+ &json_object_lh_entry_free);
if (!jso->o.c_object)
{
json_object_generic_delete(jso);
return (strcmp((const char*)k1, (const char*)k2) == 0);
}
-struct lh_table* lh_table_new(int size, const char *name,
+struct lh_table* lh_table_new(int size,
lh_entry_free_fn *free_fn,
lh_hash_fn *hash_fn,
lh_equal_fn *equal_fn)
if(!t) lh_abort("lh_table_new: calloc failed\n");
t->count = 0;
t->size = size;
- t->name = name;
t->table = (struct lh_entry*)calloc(size, sizeof(struct lh_entry));
if(!t->table) lh_abort("lh_table_new: calloc failed\n");
t->free_fn = free_fn;
return t;
}
-struct lh_table* lh_kchar_table_new(int size, const char *name,
+struct lh_table* lh_kchar_table_new(int size,
lh_entry_free_fn *free_fn)
{
- return lh_table_new(size, name, free_fn, char_hash_fn, lh_char_equal);
+ return lh_table_new(size, free_fn, char_hash_fn, lh_char_equal);
}
-struct lh_table* lh_kptr_table_new(int size, const char *name,
+struct lh_table* lh_kptr_table_new(int size,
lh_entry_free_fn *free_fn)
{
- return lh_table_new(size, name, free_fn, lh_ptr_hash, lh_ptr_equal);
+ return lh_table_new(size, free_fn, lh_ptr_hash, lh_ptr_equal);
}
void lh_table_resize(struct lh_table *t, int new_size)
struct lh_table *new_t;
struct lh_entry *ent;
- new_t = lh_table_new(new_size, t->name, NULL, t->hash_fn, t->equal_fn);
+ new_t = lh_table_new(new_size, NULL, t->hash_fn, t->equal_fn);
ent = t->head;
while(ent) {
lh_table_insert(new_t, ent->k, ent->v);
t->size = new_size;
t->head = new_t->head;
t->tail = new_t->tail;
- t->resizes++;
free(new_t);
}
{
unsigned long n;
- t->inserts++;
if(t->count >= t->size * LH_LOAD_FACTOR) lh_table_resize(t, t->size * 2);
n = h % t->size;
while( 1 ) {
if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) break;
- t->collisions++;
if ((int)++n == t->size) n = 0;
}
unsigned long n = h % t->size;
int count = 0;
- t->lookups++;
while( count < t->size ) {
if(t->table[n].k == LH_EMPTY) return NULL;
if(t->table[n].k != LH_FREED &&
*/
int count;
- /**
- * Number of collisions.
- */
- int collisions;
-
- /**
- * Number of resizes.
- */
- int resizes;
-
- /**
- * Number of lookups.
- */
- int lookups;
-
- /**
- * Number of inserts.
- */
- int inserts;
-
- /**
- * Number of deletes.
- */
- int deletes;
-
- /**
- * Name of the hash table.
- */
- const char *name;
-
/**
* The first entry.
*/
* Create a new linkhash table.
* @param size initial table size. The table is automatically resized
* although this incurs a performance penalty.
- * @param name the table name.
* @param free_fn callback function used to free memory for entries
* when lh_table_free or lh_table_delete is called.
* If NULL is provided, then memory for keys and values
* and C strings respectively.
* @return a pointer onto the linkhash table.
*/
-extern struct lh_table* lh_table_new(int size, const char *name,
+extern struct lh_table* lh_table_new(int size,
lh_entry_free_fn *free_fn,
lh_hash_fn *hash_fn,
lh_equal_fn *equal_fn);
* @param free_fn callback function used to free memory for entries.
* @return a pointer onto the linkhash table.
*/
-extern struct lh_table* lh_kchar_table_new(int size, const char *name,
+extern struct lh_table* lh_kchar_table_new(int size,
lh_entry_free_fn *free_fn);
* @param free_fn callback function used to free memory for entries.
* @return a pointer onto the linkhash table.
*/
-extern struct lh_table* lh_kptr_table_new(int size, const char *name,
+extern struct lh_table* lh_kptr_table_new(int size,
lh_entry_free_fn *free_fn);