switch_status_t switch_neighbor_free(switch_device_t device) { UNUSED(device); switch_handle_type_free(SWITCH_HANDLE_TYPE_ARP); tommy_hashtable_done(&switch_dmac_rewrite_table); tommy_hashtable_done(&switch_neighbor_dmac_table); switch_api_id_allocator_destroy(dmac_rewrite_index_allocator); return SWITCH_STATUS_SUCCESS; }
void pcore_hash_done(phash_pool *ptr) { phash_pool pool = (*ptr); if (!pool) { plog_error("%s(): Нет phash_pool!", __PRETTY_FUNCTION__); return; } plog_dbg("%s(): Очистка пула 0x%08X", __PRETTY_FUNCTION__, pool); tommy_node* i = tommy_list_head(pool->list); while (i) { tommy_node* i_next = i->next; if (!pcore_hash_deleteObject((phash_object*)&i->data)) { break; } i = i_next; } switch (pool->type) { case PHASH_FAST_SEARCH: tommy_hashdyn_done((tommy_hashdyn *)pool->hash_struct); break; case PHASH_FAST_INSERT: default: tommy_hashtable_done((tommy_hashtable *)pool->hash_struct); break; } pfree(&pool->hash_struct); pfree(&pool->list); pfree(&pool); }
switch_status_t switch_router_mac_free(switch_device_t device) { tommy_hashtable_done(&smac_rewrite_table); switch_handle_type_free(SWITCH_HANDLE_TYPE_MY_MAC); return SWITCH_STATUS_SUCCESS; }
switch_status_t switch_l3_free(switch_device_t device) { UNUSED(device); tommy_hashtable_done(&switch_l3_hash_table); switch_handle_type_free(SWITCH_HANDLE_TYPE_URPF); return SWITCH_STATUS_SUCCESS; }
void tcam_cache_destroy(tcam_cache_t *cache) { tommy_hashtable_done(&cache->hashtable); free(cache->entries); free(cache->bitmap_used); free(cache); }
void test_hashtable(void) { tommy_list list; tommy_hashtable hashtable; struct object_hash* HASH; unsigned i, n; tommy_node* p; unsigned limit; unsigned count; HASH = malloc(MAX * sizeof(struct object_hash)); for(i=0;i<MAX;++i) { HASH[i].value = i; } START("hashtable stack"); limit = 10 * sqrt(MAX); for(n=0;n<limit;++n) { tommy_list_init(&list); tommy_hashtable_init(&hashtable, limit / 2); /* insert */ for(i=0;i<n;++i) { tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashtable_insert(&hashtable, &HASH[i].hashnode, &HASH[i], HASH[i].value); } count = 0; tommy_hashtable_foreach_arg(&hashtable, count_arg, &count); if (count != n) abort(); /* remove */ p = tommy_list_head(&list); while (p) { struct object_hash* obj = p->data; p = p->next; tommy_hashtable_remove_existing(&hashtable, &obj->hashnode); } tommy_hashtable_done(&hashtable); } STOP(); START("hashtable queue"); limit = sqrt(MAX) / 8; for(n=0;n<limit;++n) { tommy_list_init(&list); tommy_hashtable_init(&hashtable, limit / 2); /* insert first run */ for(i=0;i<n;++i) { tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashtable_insert(&hashtable, &HASH[i].hashnode, &HASH[i], HASH[i].value); } count = 0; tommy_hashtable_foreach_arg(&hashtable, count_arg, &count); if (count != n) abort(); /* insert all the others */ for(;i<MAX;++i) { struct object_hash* obj; /* insert one */ tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashtable_insert(&hashtable, &HASH[i].hashnode, &HASH[i], HASH[i].value); /* remove one */ p = tommy_list_head(&list); obj = p->data; tommy_list_remove_existing(&list, p); tommy_hashtable_remove_existing(&hashtable, &obj->hashnode); } /* remove remaining */ p = tommy_list_head(&list); while (p) { struct object_hash* obj = p->data; p = p->next; tommy_hashtable_remove_existing(&hashtable, &obj->hashnode); } tommy_hashtable_done(&hashtable); } STOP(); }