cmph_uint32 chd_ph_search(cmph_t *mphf, const char *key, cmph_uint32 keylen) { register chd_ph_data_t * chd_ph = mphf->data; cmph_uint32 hl[3]; register cmph_uint32 disp,position; register cmph_uint32 probe0_num,probe1_num; register cmph_uint32 f,g,h; hash_vector(chd_ph->hl, key, keylen, hl); g = hl[0] % chd_ph->nbuckets; f = hl[1] % chd_ph->n; h = hl[2] % (chd_ph->n-1) + 1; disp = compressed_seq_query(chd_ph->cs, g); probe0_num = disp % chd_ph->n; probe1_num = disp/chd_ph->n; position = (cmph_uint32)((f + ((cmph_uint64 )h)*probe0_num + probe1_num) % chd_ph->n); return position; }
static cmph_uint32 brz_fch_search(brz_data_t *brz, const char *key, cmph_uint32 keylen, cmph_uint32 * fingerprint) { register cmph_uint32 h0; hash_vector(brz->h0, key, keylen, fingerprint); h0 = fingerprint[2] % brz->k; register cmph_uint32 m = brz->size[h0]; register cmph_uint32 b = fch_calc_b(brz->c, m); register double p1 = fch_calc_p1(m); register double p2 = fch_calc_p2(b); register cmph_uint32 h1 = hash(brz->h1[h0], key, keylen) % m; register cmph_uint32 h2 = hash(brz->h2[h0], key, keylen) % m; register cmph_uint8 mphf_bucket = 0; h1 = mixh10h11h12(b, p1, p2, h1); mphf_bucket = (cmph_uint8)((h2 + brz->g[h0][h1]) % m); return (mphf_bucket + brz->offset[h0]); }
static cmph_uint32 brz_bmz8_search(brz_data_t *brz, const char *key, cmph_uint32 keylen, cmph_uint32 * fingerprint) { register cmph_uint32 h0; hash_vector(brz->h0, key, keylen, fingerprint); h0 = fingerprint[2] % brz->k; register cmph_uint32 m = brz->size[h0]; register cmph_uint32 n = (cmph_uint32)ceil(brz->c * m); register cmph_uint32 h1 = hash(brz->h1[h0], key, keylen) % n; register cmph_uint32 h2 = hash(brz->h2[h0], key, keylen) % n; register cmph_uint8 mphf_bucket; if (h1 == h2 && ++h2 >= n) h2 = 0; mphf_bucket = (cmph_uint8)(brz->g[h0][h1] + brz->g[h0][h2]); DEBUGP("key: %s h1: %u h2: %u h0: %u\n", key, h1, h2, h0); DEBUGP("key: %s g[h1]: %u g[h2]: %u offset[h0]: %u edges: %u\n", key, brz->g[h0][h1], brz->g[h0][h2], brz->offset[h0], brz->m); DEBUGP("Address: %u\n", mphf_bucket + brz->offset[h0]); return (mphf_bucket + brz->offset[h0]); }
static int bdz_mapping(cmph_config_t *mph, bdz_graph3_t* graph3, bdz_queue_t queue) { cmph_uint32 e; int cycles = 0; cmph_uint32 hl[3]; bdz_config_data_t *bdz = (bdz_config_data_t *)mph->data; bdz_init_graph3(graph3, bdz->m, bdz->n); mph->key_source->rewind(mph->key_source->data); for (e = 0; e < mph->key_source->nkeys; ++e) { cmph_uint32 h0, h1, h2; cmph_uint32 keylen; char *key = NULL; mph->key_source->read(mph->key_source->data, &key, &keylen); hash_vector(bdz->hl, key, keylen,hl); h0 = hl[0] % bdz->r; h1 = hl[1] % bdz->r + bdz->r; h2 = hl[2] % bdz->r + (bdz->r << 1); mph->key_source->dispose(mph->key_source->data, key, keylen); bdz_add_edge(graph3,h0,h1,h2); } cycles = bdz_generate_queue(bdz->m, bdz->n, queue, graph3); return (cycles == 0); }
cmph_uint8 chd_ph_mapping(cmph_config_t *mph, chd_ph_bucket_t * buckets, chd_ph_item_t * items, cmph_uint32 *max_bucket_size) { register cmph_uint32 i = 0, g = 0; cmph_uint32 hl[3]; chd_ph_config_data_t *chd_ph = (chd_ph_config_data_t *)mph->data; char * key = NULL; cmph_uint32 keylen = 0; chd_ph_map_item_t * map_item; chd_ph_map_item_t * map_items = malloc(chd_ph->m*sizeof(chd_ph_map_item_t)); register cmph_uint32 mapping_iterations = 1000; *max_bucket_size = 0; while(1) { mapping_iterations--; if (chd_ph->hl) hash_state_destroy(chd_ph->hl); chd_ph->hl = hash_state_new(chd_ph->hashfunc, chd_ph->m); chd_ph_bucket_clean(buckets, chd_ph->nbuckets); mph->key_source->rewind(mph->key_source->data); for(i = 0; i < chd_ph->m; i++) { mph->key_source->read(mph->key_source->data, &key, &keylen); hash_vector(chd_ph->hl, key, keylen, hl); map_item = (map_items + i); g = hl[0] % chd_ph->nbuckets; map_item->f = hl[1] % chd_ph->n; map_item->h = hl[2] % (chd_ph->n - 1) + 1; map_item->bucket_num=g; mph->key_source->dispose(mph->key_source->data, key, keylen); // if(buckets[g].size == (chd_ph->keys_per_bucket << 2)) // { // DEBUGP("BUCKET = %u -- SIZE = %u -- MAXIMUM SIZE = %u\n", g, buckets[g].size, (chd_ph->keys_per_bucket << 2)); // goto error; // } buckets[g].size++; if(buckets[g].size > *max_bucket_size) { *max_bucket_size = buckets[g].size; } } buckets[0].items_list = 0; for(i = 1; i < chd_ph->nbuckets; i++) { buckets[i].items_list = buckets[i-1].items_list + buckets[i - 1].size; buckets[i - 1].size = 0; }; buckets[i - 1].size = 0; for(i = 0; i < chd_ph->m; i++) { map_item = (map_items + i); if(!chd_ph_bucket_insert(buckets, map_items, items, chd_ph->nbuckets, i)) break; } if(i == chd_ph->m) { free(map_items); return 1; // SUCCESS } if(mapping_iterations == 0) { goto error; } } error: free(map_items); hash_state_destroy(chd_ph->hl); chd_ph->hl = NULL; return 0; // FAILURE }