int ethernet_dissector_display_set(const enum display_type dtype) { void *key_ptr = NULL; hi_iterator_t * it = NULL; struct protocol_dissector * dis = NULL; uint32_t keylen = 0; int rc; if ((rc = hi_iterator_create(ethernet_dissector_hash, &it)) != 0) { err("Could not create iterator\n"); return (EAGAIN); } while (hi_iterator_getnext(it, (void **) &dis, &key_ptr, &keylen) == 0 && dis != NULL) { dis->display_set(dtype); } hi_iterator_fini(it); return (0); }
int hi_rehash(hi_handle_t *hi_hndl, uint32_t new_table_size) { int ret, auto_rehash; void *key, *data; uint32_t keylen; hi_handle_t *hi_handle; hi_iterator_t *iterator; /* create a clean handle for the new structure */ ret = lhi_create_vanilla_hdnl(&hi_handle); if (ret != SUCCESS) return ret; /* we take over the original settings done * by the user taken at hi_create() time */ lhi_transform_hndl_2_hndl(hi_hndl, hi_handle); hi_handle->table_size = new_table_size; /* Allocate memory fot accounting the number of * elements within every bucket in the table. */ ret = XMALLOC((void **) &hi_handle->bucket_size, hi_handle->table_size * sizeof(*hi_handle->bucket_size)); if (ret != 0) { return HI_ERR_SYSTEM; } /* 0 objects in the list at start-up */ hi_handle->no_objects = 0; /* Initiate mutex lock if build with thread * support. */ hi_handle->mutex_lock = NULL; ret = lhi_pthread_mutex_init(&hi_handle->mutex_lock, NULL); if (ret != 0) { return HI_ERR_SYSTEM; } /* Create internal data structure for * list, array or rbtree */ switch (hi_handle->coll_eng) { case COLL_ENG_LIST: case COLL_ENG_LIST_HASH: case COLL_ENG_LIST_MTF: case COLL_ENG_LIST_MTF_HASH: ret = lhi_create_eng_list(hi_handle); if (ret != SUCCESS) return ret; break; case COLL_ENG_ARRAY: case COLL_ENG_ARRAY_HASH: case COLL_ENG_ARRAY_DYN: case COLL_ENG_ARRAY_DYN_HASH: ret = lhi_create_eng_array(hi_handle); if (ret != SUCCESS) return ret; break; case COLL_ENG_RBTREE: ret = lhi_create_eng_rbtree(hi_handle); if (ret != SUCCESS) return ret; break; default: return HI_ERR_INTERNAL; break; } ret = hi_iterator_create(hi_hndl, &iterator); if (ret != SUCCESS) return ret; auto_rehash = hi_handle->rehash_auto; hi_handle->rehash_auto = 0; while ((ret = hi_iterator_getnext(iterator, &data, &key, &keylen)) == SUCCESS) { ret = hi_insert(hi_handle, key, keylen, data); if (ret != SUCCESS) { hi_iterator_fini(iterator); hi_fini(hi_handle); hi_handle->rehash_auto = auto_rehash; return ret; } } hi_handle->rehash_auto = auto_rehash; /* verify that no error occured during iterator run */ if (ret != HI_ERR_NODATA) { hi_iterator_fini(iterator); return ret; } hi_iterator_fini(iterator); /* free old hashish handle */ lhi_fini_internal(hi_hndl); memcpy(hi_hndl, hi_handle, sizeof(*hi_hndl)); return SUCCESS; }
static void check_iterator(enum coll_eng engine, enum hash_alg hash_alg) { int ret, i; hi_handle_t *hi_hndl; struct hi_init_set hi_set; hi_iterator_t *iterator; void *data_ptr = (void *) 0xdeadbeef; void *key; uint32_t keylen; hi_set_zero(&hi_set); ret = hi_set_bucket_size(&hi_set, 100); assert(ret == 0); ret = hi_set_hash_alg(&hi_set, hash_alg); assert(ret == 0); ret = hi_set_coll_eng(&hi_set, engine); assert(ret == 0); ret = hi_set_key_cmp_func(&hi_set, hi_cmp_str); assert(ret == 0); /* we need aditional arguments for ARRAY based engines */ switch (engine) { case COLL_ENG_ARRAY: case COLL_ENG_ARRAY_HASH: case COLL_ENG_ARRAY_DYN: case COLL_ENG_ARRAY_DYN_HASH: ret = hi_set_coll_eng_array_size(&hi_set, 20); assert(ret == 0); break; default: break; }; ret = hi_create(&hi_hndl, &hi_set); if (ret != 0) print_error(ret); assert(ret == 0); ret = hi_insert(hi_hndl, (void *) "key", sizeof("key"), "data"); assert(ret == 0); ret = hi_insert(hi_hndl, (void *) "key1", sizeof("key1"), "data1"); assert(ret == 0); ret = hi_insert(hi_hndl, (void *) "key2", sizeof("key2"), "data2"); assert(ret == 0); ret = hi_iterator_create(hi_hndl, &iterator); if (ret != 0) return; for (i = 0; i < 2; i++) { bool got_key[] = { 0, 0, 0 }; unsigned int j; for (j = 0 ; j < 3 ; j++) { data_ptr = NULL; ret = hi_iterator_getnext(iterator, &data_ptr, &key, &keylen); assert(ret == 0); assert(data_ptr); if (strcmp(data_ptr, "data") == 0) { assert(!got_key[0]); got_key[0] = true; continue; } if (strcmp(data_ptr, "data1") == 0) { assert(!got_key[1]); got_key[1] = true; continue; } assert (strcmp(data_ptr, "data2") == 0); assert(!got_key[2]); got_key[2] = true; } ret = hi_iterator_getnext(iterator, &data_ptr, &key, &keylen); assert (ret == HI_ERR_NODATA); ret = hi_iterator_reset(iterator); assert(ret == 0); } hi_iterator_fini(iterator); ret = hi_remove(hi_hndl, (void *) "key", sizeof("key"), &data_ptr); assert(ret == 0); ret = hi_remove(hi_hndl, (void *) "key1", sizeof("key1"), &data_ptr); assert(ret == 0); ret = hi_remove(hi_hndl, (void *) "key2", sizeof("key2"), &data_ptr); assert(ret == 0); ret = hi_fini(hi_hndl); assert(ret == 0); fputs("passed\n", stdout); }