static void search_file(struct snapraid_state* state, const char* path, data_off_t size, int64_t mtime_sec, int mtime_nsec) { struct snapraid_search_file* file; tommy_uint32_t file_hash; file = malloc_nofail(sizeof(struct snapraid_search_file)); file->path = strdup_nofail(path); file->size = size; file->mtime_sec = mtime_sec; file->mtime_nsec = mtime_nsec; file_hash = file_stamp_hash(file->size, file->mtime_sec, file->mtime_nsec); tommy_hashdyn_insert(&state->searchset, &file->node, file, file_hash); }
void pcore_hash_insert(phash_pool pool, const puint32 value, void* const data) { if (!pool) { plog_error("%s(): Нет phash_pool!", __PRETTY_FUNCTION__); return; } plog_dbg("%s(): Вставка ресурсов со значением '%d'", __PRETTY_FUNCTION__, value); phash_object object = pcore_hash_newObject(value, data); tommy_list_insert_tail(pool->list, &object->list_node, object); switch (pool->type) { case PHASH_FAST_SEARCH: tommy_hashdyn_insert((tommy_hashdyn *)pool->hash_struct, &object->hash_node, object, tommy_inthash_u32(object->value)); break; case PHASH_FAST_INSERT: default: tommy_hashtable_insert((tommy_hashtable *)pool->hash_struct, &object->hash_node, object, tommy_inthash_u32(object->value)); break; } }
static int _add_entry_index(int type, void *entry, unsigned int size, struct entry_hash_node *data) { tommy_hash_t hash=hashlittle(entry, size, type); tommy_hashdyn_insert(&entry_hash, &(data->node), data, hash); return 0; }
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(); }