static p_link_node hash_find_node(hash_table *table, uint64_t key) { bool first = true; hash_node *hn; link_list *l = get_link_list(table, key); p_link_node ln = link_list_first(l); while (ln) { hn = (hash_node *) ln->data; if (hn->key == key) { if (!first) { /* put the lastest item to the head of the linked list */ link_list_remove(l, ln); link_list_push(l, ln); } return ln; } ln = link_list_get_next(l, ln); first = false; } return NULL; }
static p_link_node hash_find_node(hash_table *table, uint64_t key) { hash_node *hn; link_list *l = get_link_list(table, key); p_link_node ln = link_list_first(l); table->total_visit++; while (ln) { hn = (hash_node *)ln->data; table->total_key_compared++; if (hn->key == key) { hn->access_time = time(0); hn->visit_cnt++; /* Put the lastest item to the head of the linked list */ (void)link_list_remove(l, ln); link_list_push(l, ln); return ln; } ln = link_list_get_next(l, ln); } return NULL; }
static int release_resources(uint64_t key) { link_list *list; p_link_node ln, tln; mysql_table_item_t *item; item = hash_find(ctx.table, key); if (item != NULL) { list = item->list; ln = link_list_first(list); while (ln) { tln = ln; ln = link_list_get_next(list, ln); link_list_remove(list, tln); tc_pfree(ctx.pool, tln->data); tc_pfree(ctx.pool, tln); } tc_pfree(ctx.pool, item); tc_pfree(ctx.pool, list); hash_del(ctx.table, ctx.pool, key); } return TC_OK; }
inline p_link_node link_list_pop_tail(link_list *l) { p_link_node tail = link_list_tail(l); if (!tail) { return tail; } return link_list_remove(l, tail); }
inline p_link_node link_list_pop_first(link_list *l) { p_link_node first = link_list_first(l); if (!first) { return first; } return link_list_remove(l, first); }
bool hash_del(hash_table *table, uint64_t key) { link_list *l = get_link_list(table, key); p_link_node ln = hash_find_node(table, key); if(ln != NULL){ table->total--; link_list_remove(l, ln); link_node_internal_free(ln); free(ln); return true; }else{ return false; } }
bool hash_del(hash_table *table, tc_pool_t *pool, uint64_t key) { link_list *l = get_link_list(table, key); p_link_node ln = hash_find_node(table, key); if (ln != NULL) { table->total--; link_list_remove(l, ln); tc_pfree(pool, ln->data); tc_pfree(pool, ln); return true; } else { return false; } }