Lines Matching refs:t
432 struct lh_table *t; in lh_table_new() local
434 t = (struct lh_table*)calloc(1, sizeof(struct lh_table)); in lh_table_new()
435 if(!t) lh_abort("lh_table_new: calloc failed\n"); in lh_table_new()
436 t->count = 0; in lh_table_new()
437 t->size = size; in lh_table_new()
438 t->name = name; in lh_table_new()
439 t->table = (struct lh_entry*)calloc(size, sizeof(struct lh_entry)); in lh_table_new()
440 if(!t->table) lh_abort("lh_table_new: calloc failed\n"); in lh_table_new()
441 t->free_fn = free_fn; in lh_table_new()
442 t->hash_fn = hash_fn; in lh_table_new()
443 t->equal_fn = equal_fn; in lh_table_new()
444 for(i = 0; i < size; i++) t->table[i].k = LH_EMPTY; in lh_table_new()
445 return t; in lh_table_new()
460 void lh_table_resize(struct lh_table *t, int new_size) in lh_table_resize() argument
465 new_t = lh_table_new(new_size, t->name, NULL, t->hash_fn, t->equal_fn); in lh_table_resize()
466 ent = t->head; in lh_table_resize()
471 free(t->table); in lh_table_resize()
472 t->table = new_t->table; in lh_table_resize()
473 t->size = new_size; in lh_table_resize()
474 t->head = new_t->head; in lh_table_resize()
475 t->tail = new_t->tail; in lh_table_resize()
476 t->resizes++; in lh_table_resize()
480 void lh_table_free(struct lh_table *t) in lh_table_free() argument
483 for(c = t->head; c != NULL; c = c->next) { in lh_table_free()
484 if(t->free_fn) { in lh_table_free()
485 t->free_fn(c); in lh_table_free()
488 free(t->table); in lh_table_free()
489 free(t); in lh_table_free()
493 int lh_table_insert(struct lh_table *t, void *k, const void *v) in lh_table_insert() argument
497 t->inserts++; in lh_table_insert()
498 if(t->count >= t->size * LH_LOAD_FACTOR) lh_table_resize(t, t->size * 2); in lh_table_insert()
500 h = t->hash_fn(k); in lh_table_insert()
501 n = h % t->size; in lh_table_insert()
504 if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) break; in lh_table_insert()
505 t->collisions++; in lh_table_insert()
506 if ((int)++n == t->size) n = 0; in lh_table_insert()
509 t->table[n].k = k; in lh_table_insert()
510 t->table[n].v = v; in lh_table_insert()
511 t->count++; in lh_table_insert()
513 if(t->head == NULL) { in lh_table_insert()
514 t->head = t->tail = &t->table[n]; in lh_table_insert()
515 t->table[n].next = t->table[n].prev = NULL; in lh_table_insert()
517 t->tail->next = &t->table[n]; in lh_table_insert()
518 t->table[n].prev = t->tail; in lh_table_insert()
519 t->table[n].next = NULL; in lh_table_insert()
520 t->tail = &t->table[n]; in lh_table_insert()
527 struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k) in lh_table_lookup_entry() argument
529 unsigned long h = t->hash_fn(k); in lh_table_lookup_entry()
530 unsigned long n = h % t->size; in lh_table_lookup_entry()
533 t->lookups++; in lh_table_lookup_entry()
534 while( count < t->size ) { in lh_table_lookup_entry()
535 if(t->table[n].k == LH_EMPTY) return NULL; in lh_table_lookup_entry()
536 if(t->table[n].k != LH_FREED && in lh_table_lookup_entry()
537 t->equal_fn(t->table[n].k, k)) return &t->table[n]; in lh_table_lookup_entry()
538 if ((int)++n == t->size) n = 0; in lh_table_lookup_entry()
545 const void* lh_table_lookup(struct lh_table *t, const void *k) in lh_table_lookup() argument
548 lh_table_lookup_ex(t, k, &result); in lh_table_lookup()
552 json_bool lh_table_lookup_ex(struct lh_table* t, const void* k, void **v) in lh_table_lookup_ex() argument
554 struct lh_entry *e = lh_table_lookup_entry(t, k); in lh_table_lookup_ex()
563 int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e) in lh_table_delete_entry() argument
565 …ptrdiff_t n = (ptrdiff_t)(e - t->table); /* CAW: fixed to be 64bit nice, still need the crazy nega… in lh_table_delete_entry()
570 if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) return -1; in lh_table_delete_entry()
571 t->count--; in lh_table_delete_entry()
572 if(t->free_fn) t->free_fn(e); in lh_table_delete_entry()
573 t->table[n].v = NULL; in lh_table_delete_entry()
574 t->table[n].k = LH_FREED; in lh_table_delete_entry()
575 if(t->tail == &t->table[n] && t->head == &t->table[n]) { in lh_table_delete_entry()
576 t->head = t->tail = NULL; in lh_table_delete_entry()
577 } else if (t->head == &t->table[n]) { in lh_table_delete_entry()
578 t->head->next->prev = NULL; in lh_table_delete_entry()
579 t->head = t->head->next; in lh_table_delete_entry()
580 } else if (t->tail == &t->table[n]) { in lh_table_delete_entry()
581 t->tail->prev->next = NULL; in lh_table_delete_entry()
582 t->tail = t->tail->prev; in lh_table_delete_entry()
584 t->table[n].prev->next = t->table[n].next; in lh_table_delete_entry()
585 t->table[n].next->prev = t->table[n].prev; in lh_table_delete_entry()
587 t->table[n].next = t->table[n].prev = NULL; in lh_table_delete_entry()
592 int lh_table_delete(struct lh_table *t, const void *k) in lh_table_delete() argument
594 struct lh_entry *e = lh_table_lookup_entry(t, k); in lh_table_delete()
596 return lh_table_delete_entry(t, e); in lh_table_delete()
599 int lh_table_length(struct lh_table *t) in lh_table_length() argument
601 return t->count; in lh_table_length()