void cheap_tcam_insert(cheap_tcam_t *tcam, uint8_t *mask, uint8_t *key, cheap_tcam_node *node, void *data) { tommy_list *hashmaps = &tcam->hashmaps; tcam_hashmap_t *tcam_hashmap; uint32_t hash = hashlittle(key, tcam->key_size, 0); tommy_node* elem = tommy_list_head(hashmaps); while(elem) { tcam_hashmap = (tcam_hashmap_t *) elem->data; if(!memcmp(mask, tcam_hashmap->mask, tcam->key_size)) { tommy_hashlin_insert(&tcam_hashmap->hashmap, node, data, hash); return; } elem = elem->next; } tcam_hashmap = malloc(sizeof(tcam_hashmap_t)); tommy_hashlin_init(&tcam_hashmap->hashmap); tcam_hashmap->mask = malloc(tcam->key_size); memcpy(tcam_hashmap->mask, mask, tcam->key_size); tommy_list_insert_head(hashmaps, &tcam_hashmap->node, tcam_hashmap); tommy_hashlin_insert(&tcam_hashmap->hashmap, node, data, hash); }
void mirroring_init() { rmt_mirroring_cb = cb_init(MIRRORING_CB_SIZE, CB_WRITE_BLOCK, CB_READ_BLOCK); tommy_hashlin_init(&mirroring_mappings); pthread_create(&mirroring_thread, NULL, mirroring_loop, NULL); }
void switchlink_db_init() { tommy_trie_inplace_init(&switchlink_db_handle_obj_map); tommy_trie_inplace_init(&switchlink_db_interface_obj_map); tommy_trie_inplace_init(&switchlink_db_bridge_obj_map); tommy_hashlin_init(&switchlink_db_mac_obj_hash); tommy_list_init(&switchlink_db_mac_obj_list); tommy_list_init(&switchlink_db_neigh_obj_list); tommy_list_init(&switchlink_db_ecmp_obj_list); tommy_list_init(&switchlink_db_route_obj_list); }
void init_hash_table(void *ht, void *ll) { tommy_hashlin_init(ht); tommy_list_init(ll); }
void mirroring_init() { tommy_hashlin_init(&mirroring_mappings); }
void test_hashlin(void) { tommy_list list; tommy_hashlin hashlin; 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("hashlin stack"); limit = 10 * sqrt(MAX); for(n=0;n<limit;++n) { tommy_list_init(&list); tommy_hashlin_init(&hashlin); /* insert */ for(i=0;i<n;++i) { tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashlin_insert(&hashlin, &HASH[i].hashnode, &HASH[i], HASH[i].value); } count = 0; tommy_hashlin_foreach_arg(&hashlin, 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_hashlin_remove_existing(&hashlin, &obj->hashnode); } tommy_hashlin_done(&hashlin); } STOP(); START("hashlin queue"); limit = sqrt(MAX) / 8; for(n=0;n<limit;++n) { tommy_list_init(&list); tommy_hashlin_init(&hashlin); /* insert first run */ for(i=0;i<n;++i) { tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashlin_insert(&hashlin, &HASH[i].hashnode, &HASH[i], HASH[i].value); } count = 0; tommy_hashlin_foreach_arg(&hashlin, 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_hashlin_insert(&hashlin, &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_hashlin_remove_existing(&hashlin, &obj->hashnode); } /* remove remaining */ p = tommy_list_head(&list); while (p) { struct object_hash* obj = p->data; p = p->next; tommy_hashlin_remove_existing(&hashlin, &obj->hashnode); } tommy_hashlin_done(&hashlin); } STOP(); }