void disk_free(struct snapraid_disk* disk) { tommy_list_foreach(&disk->filelist, (tommy_foreach_func*)file_free); tommy_list_foreach(&disk->deletedlist, (tommy_foreach_func*)file_free); tommy_tree_foreach(&disk->fs_file, (tommy_foreach_func*)chunk_free); tommy_hashdyn_done(&disk->inodeset); tommy_hashdyn_done(&disk->pathset); tommy_hashdyn_done(&disk->stampset); tommy_list_foreach(&disk->linklist, (tommy_foreach_func*)link_free); tommy_hashdyn_done(&disk->linkset); tommy_list_foreach(&disk->dirlist, (tommy_foreach_func*)dir_free); tommy_hashdyn_done(&disk->dirset); free(disk); }
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); }
static void test_tommy(void) { tommy_array array; tommy_arrayblk arrayblk; tommy_arrayblkof arrayblkof; tommy_hashdyn hashdyn; tommy_hashdyn_node node[TOMMY_SIZE]; unsigned i; tommy_array_init(&array); tommy_arrayblk_init(&arrayblk); tommy_arrayblkof_init(&arrayblkof, sizeof(unsigned)); for(i=0;i<TOMMY_SIZE;++i) { tommy_array_insert(&array, &node[i]); tommy_arrayblk_insert(&arrayblk, &node[i]); tommy_arrayblkof_grow(&arrayblkof, i + 1); *(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) = i; } if (tommy_array_memory_usage(&array) < TOMMY_SIZE * sizeof(void*)) goto bail; if (tommy_arrayblk_memory_usage(&arrayblk) < TOMMY_SIZE * sizeof(void*)) goto bail; if (tommy_arrayblkof_memory_usage(&arrayblkof) < TOMMY_SIZE * sizeof(unsigned)) goto bail; for(i=0;i<TOMMY_SIZE;++i) { if (tommy_array_get(&array, i) != &node[i]) goto bail; if (tommy_arrayblk_get(&arrayblk, i) != &node[i]) goto bail; if (*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) != i) goto bail; } tommy_arrayblkof_done(&arrayblkof); tommy_arrayblk_done(&arrayblk); tommy_array_done(&array); tommy_hashdyn_init(&hashdyn); for(i=0;i<TOMMY_SIZE;++i) tommy_hashdyn_insert(&hashdyn, &node[i], &node[i], i % 64); if (tommy_hashdyn_count(&hashdyn) != TOMMY_SIZE) goto bail; if (tommy_hashdyn_memory_usage(&hashdyn) < TOMMY_SIZE * sizeof(void*)) goto bail; for(i=0;i<TOMMY_SIZE/2;++i) tommy_hashdyn_remove_existing(&hashdyn, &node[i]); for(i=0;i<TOMMY_SIZE/2;++i) if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) != 0) goto bail; for(i=TOMMY_SIZE/2;i<TOMMY_SIZE;++i) if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) == 0) goto bail; if (tommy_hashdyn_count(&hashdyn) != 0) goto bail; tommy_hashdyn_done(&hashdyn); return; bail: /* LCOV_EXCL_START */ fprintf(stderr, "Failed tommy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ }
void test_hashdyn(void) { tommy_list list; tommy_hashdyn hashdyn; 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("hashdyn stack"); limit = 10 * sqrt(MAX); for(n=0;n<limit;++n) { tommy_list_init(&list); tommy_hashdyn_init(&hashdyn); /* insert */ for(i=0;i<n;++i) { tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashdyn_insert(&hashdyn, &HASH[i].hashnode, &HASH[i], HASH[i].value); } count = 0; tommy_hashdyn_foreach_arg(&hashdyn, 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_hashdyn_remove_existing(&hashdyn, &obj->hashnode); } tommy_hashdyn_done(&hashdyn); } STOP(); START("hashdyn queue"); limit = sqrt(MAX) / 8; for(n=0;n<limit;++n) { tommy_list_init(&list); tommy_hashdyn_init(&hashdyn); /* insert first run */ for(i=0;i<n;++i) { tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]); tommy_hashdyn_insert(&hashdyn, &HASH[i].hashnode, &HASH[i], HASH[i].value); } count = 0; tommy_hashdyn_foreach_arg(&hashdyn, 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_hashdyn_insert(&hashdyn, &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_hashdyn_remove_existing(&hashdyn, &obj->hashnode); } /* remove remaining */ p = tommy_list_head(&list); while (p) { struct object_hash* obj = p->data; p = p->next; tommy_hashdyn_remove_existing(&hashdyn, &obj->hashnode); } tommy_hashdyn_done(&hashdyn); } STOP(); }