static int _get_entry_index(int type, void *entry, unsigned int size) { struct entry_hash_node *h; tommy_hash_t hash=hashlittle(entry, size, type); h = tommy_hashdyn_search(&entry_hash, entry_hash_cmp, entry, hash); if(h) return h->entry_handle; return -1; }
void* pcore_hash_search(phash_pool pool, const puint32 value) { if (!pool) { plog_error("%s(): Нет phash_pool!", __PRETTY_FUNCTION__); return NULL; } plog_dbg("%s(): Поиск в пуле 0x%08X значения '%d'", __PRETTY_FUNCTION__, pool, value); phash_object ret = NULL; switch (pool->type) { case PHASH_FAST_SEARCH: ret = tommy_hashdyn_search((tommy_hashdyn *)pool->hash_struct, compare_hash_uint32, &value, tommy_inthash_u32(value)); break; case PHASH_FAST_INSERT: default: ret = tommy_hashtable_search((tommy_hashtable *)pool->hash_struct, compare_hash_uint32, &value, tommy_inthash_u32(value)); break; } return ret->data; }
int state_search_fetch(struct snapraid_state* state, int prevhash, struct snapraid_block* missing_block, unsigned char* buffer) { struct snapraid_search_file* file; tommy_uint32_t file_hash; struct search_file_compare_arg arg; arg.state = state; arg.block = missing_block; arg.file = block_file_get(missing_block); arg.buffer = buffer; arg.offset = state->block_size * (data_off_t)block_file_pos(missing_block); arg.read_size = block_file_size(missing_block, state->block_size); arg.prevhash = prevhash; file_hash = file_stamp_hash(arg.file->size, arg.file->mtime_sec, arg.file->mtime_nsec); /* search in the hashtable, and also check if the data matches the hash */ file = tommy_hashdyn_search(&state->searchset, search_file_compare, &arg, file_hash); if (!file) return -1; /* if found, buffer is already set with data */ return 0; }