Example #1
0
/** cmph_uint32 fch_search(void *packed_mphf, const char *key, cmph_uint32 keylen);
 *  \brief Use the packed mphf to do a search. 
 *  \param  packed_mphf pointer to the packed mphf
 *  \param key key to be hashed
 *  \param keylen key legth in bytes
 *  \return The mphf value
 */
cmph_uint32 fch_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
	register cmph_uint8 *h1_ptr = packed_mphf;
	register CMPH_HASH h1_type  = *((cmph_uint32 *)h1_ptr);
	h1_ptr += 4;

	register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
	register CMPH_HASH h2_type  = *((cmph_uint32 *)h2_ptr);
	h2_ptr += 4;
	
	register cmph_uint32 *g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type));
	
	register cmph_uint32 m = *g_ptr++;  

	register cmph_uint32 b = *g_ptr++;  

	register double p1 = (double)(*((cmph_uint64 *)g_ptr));
	g_ptr += 2;

	register double p2 = (double)(*((cmph_uint64 *)g_ptr));
	g_ptr += 2;

	register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % m; 
	register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % m;

	h1 = mixh10h11h12 (b, p1, p2, h1);
	return (h2 + g_ptr[h1]) % m;
}
Example #2
0
/** \fn void bmz8_pack(cmph_t *mphf, void *packed_mphf);
 *  \brief Support the ability to pack a perfect hash function into a preallocated contiguous memory space pointed by packed_mphf.
 *  \param mphf pointer to the resulting mphf
 *  \param packed_mphf pointer to the contiguous memory area used to store the resulting mphf. The size of packed_mphf must be at least cmph_packed_size()
 */
void bmz8_pack(cmph_t *mphf, void *packed_mphf)
{
	bmz8_data_t *data = (bmz8_data_t *)mphf->data;
	cmph_uint8 * ptr = (cmph_uint8 *)packed_mphf;

	// packing h1 type
	CMPH_HASH h1_type = hash_get_type(data->hashes[0]);
	*((cmph_uint32 *) ptr) = h1_type;
	ptr += sizeof(cmph_uint32);

	// packing h1
	hash_state_pack(data->hashes[0], ptr);
	ptr += hash_state_packed_size(h1_type);

	// packing h2 type
	CMPH_HASH h2_type = hash_get_type(data->hashes[1]);
	*((cmph_uint32 *) ptr) = h2_type;
	ptr += sizeof(cmph_uint32);

	// packing h2
	hash_state_pack(data->hashes[1], ptr);
	ptr += hash_state_packed_size(h2_type);

	// packing n
	*ptr++ = data->n;

	// packing g
	memcpy(ptr, data->g, sizeof(cmph_uint8)*data->n);
}
Example #3
0
/** cmph_uint32 bmz_search(void *packed_mphf, const char *key, cmph_uint32 keylen);
 *  \brief Use the packed mphf to do a search. 
 *  \param  packed_mphf pointer to the packed mphf
 *  \param key key to be hashed
 *  \param keylen key legth in bytes
 *  \return The mphf value
 */
cmph_uint32 bmz_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
	register cmph_uint8 *h1_ptr = packed_mphf;
	register CMPH_HASH h1_type  = *((cmph_uint32 *)h1_ptr);
    register cmph_uint8 *h2_ptr;
    register CMPH_HASH h2_type;
    register cmph_uint32 *g_ptr;
    register cmph_uint32 n;
    register cmph_uint32 h1;
    register cmph_uint32 h2;
	h1_ptr += 4;

	h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
	h2_type  = *((cmph_uint32 *)h2_ptr);
	h2_ptr += 4;
	
	g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type));
	
	n = *g_ptr++;  
	
	h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n; 
	h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n; 
	if (h1 == h2 && ++h2 > n) h2 = 0;
	return (g_ptr[h1] + g_ptr[h2]);	
}
Example #4
0
/** \fn cmph_uint32 bmz8_packed_size(cmph_t *mphf);
 *  \brief Return the amount of space needed to pack mphf.
 *  \param mphf pointer to a mphf
 *  \return the size of the packed function or zero for failures
 */
cmph_uint32 bmz8_packed_size(cmph_t *mphf)
{
	bmz8_data_t *data = (bmz8_data_t *)mphf->data;
	CMPH_HASH h1_type = hash_get_type(data->hashes[0]);
	CMPH_HASH h2_type = hash_get_type(data->hashes[1]);

	return (cmph_uint32)(sizeof(CMPH_ALGO) + hash_state_packed_size(h1_type) + hash_state_packed_size(h2_type) +
			2*sizeof(cmph_uint32) + sizeof(cmph_uint8) + sizeof(cmph_uint8)*data->n);
}
Example #5
0
/** \fn cmph_uint32 fch_packed_size(cmph_t *mphf);
 *  \brief Return the amount of space needed to pack mphf.
 *  \param mphf pointer to a mphf
 *  \return the size of the packed function or zero for failures
 */ 
cmph_uint32 fch_packed_size(cmph_t *mphf)
{
	fch_data_t *data = (fch_data_t *)mphf->data;
	CMPH_HASH h1_type = hash_get_type(data->h1); 
	CMPH_HASH h2_type = hash_get_type(data->h2); 

	return (sizeof(CMPH_ALGO) + hash_state_packed_size(h1_type) + hash_state_packed_size(h2_type) + 
			4*sizeof(cmph_uint32) + 2*sizeof(double) + sizeof(cmph_uint32)*(data->b));
}
Example #6
0
static cmph_uint32 brz_fch_search_packed(cmph_uint32 *packed_mphf, const char *key, cmph_uint32 keylen, cmph_uint32 * fingerprint)
{
	register CMPH_HASH h0_type = *packed_mphf++;
	
	register cmph_uint32 *h0_ptr = packed_mphf;
	packed_mphf = (cmph_uint32 *)(((cmph_uint8 *)packed_mphf) + hash_state_packed_size(h0_type)); 
	
	register cmph_uint32 k = *packed_mphf++;

	register double c = (double)(*((cmph_uint64*)packed_mphf));
	packed_mphf += 2;

	register CMPH_HASH h1_type = *packed_mphf++; 

	register CMPH_HASH h2_type = *packed_mphf++; 

	register cmph_uint8 * size = (cmph_uint8 *) packed_mphf;
	packed_mphf = (cmph_uint32 *)(size + k);  
	
	register cmph_uint32 * offset = packed_mphf;
	packed_mphf += k;
	
	register cmph_uint32 h0;
	
	hash_vector_packed(h0_ptr, h0_type, key, keylen, fingerprint);
	h0 = fingerprint[2] % k;
	
	register cmph_uint32 m = size[h0];
	register cmph_uint32 b = fch_calc_b(c, m);
	register double p1 = fch_calc_p1(m);
	register double p2 = fch_calc_p2(b);
	
	#if defined (__ia64) || defined (__x86_64__)
		register cmph_uint64 * g_is_ptr = (cmph_uint64 *)packed_mphf;
	#else
		register cmph_uint32 * g_is_ptr = packed_mphf;
	#endif
	
	register cmph_uint8 * h1_ptr = (cmph_uint8 *) g_is_ptr[h0];
	
	register cmph_uint8 * h2_ptr = h1_ptr + hash_state_packed_size(h1_type);

	register cmph_uint8 * g = h2_ptr + hash_state_packed_size(h2_type);
	
	register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % m;
	register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % m;

	register cmph_uint8 mphf_bucket = 0;
	h1 = mixh10h11h12(b, p1, p2, h1);
	mphf_bucket = (cmph_uint8)((h2 + g[h1]) % m);
	return (mphf_bucket + offset[h0]);
}
Example #7
0
static cmph_uint32 brz_bmz8_search_packed(cmph_uint32 *packed_mphf, const char *key, cmph_uint32 keylen, cmph_uint32 * fingerprint)
{
	register CMPH_HASH h0_type = *packed_mphf++;
	register cmph_uint32 *h0_ptr = packed_mphf;
	packed_mphf = (cmph_uint32 *)(((cmph_uint8 *)packed_mphf) + hash_state_packed_size(h0_type)); 
	
	register cmph_uint32 k = *packed_mphf++;

	register double c = (double)(*((cmph_uint64*)packed_mphf));
	packed_mphf += 2;

	register CMPH_HASH h1_type = *packed_mphf++; 
	
	register CMPH_HASH h2_type = *packed_mphf++; 

	register cmph_uint8 * size = (cmph_uint8 *) packed_mphf;
	packed_mphf = (cmph_uint32 *)(size + k);  
	
	register cmph_uint32 * offset = packed_mphf;
	packed_mphf += k;

	register cmph_uint32 h0;
	
	hash_vector_packed(h0_ptr, h0_type, key, keylen, fingerprint);
	h0 = fingerprint[2] % k;
	
	register cmph_uint32 m = size[h0];
	register cmph_uint32 n = (cmph_uint32)ceil(c * m);

	#if defined (__ia64) || defined (__x86_64__)
		register cmph_uint64 * g_is_ptr = (cmph_uint64 *)packed_mphf;
	#else
		register cmph_uint32 * g_is_ptr = packed_mphf;
	#endif
	
	register cmph_uint8 * h1_ptr = (cmph_uint8 *) g_is_ptr[h0];
	
	register cmph_uint8 * h2_ptr = h1_ptr + hash_state_packed_size(h1_type);

	register cmph_uint8 * g = h2_ptr + hash_state_packed_size(h2_type);
	
	register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n;
	register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n;

	register cmph_uint8 mphf_bucket;
		
	if (h1 == h2 && ++h2 >= n) h2 = 0;
	mphf_bucket = (cmph_uint8)(g[h1] + g[h2]); 
	DEBUGP("key: %s h1: %u h2: %u h0: %u\n", key, h1, h2, h0);
	DEBUGP("Address: %u\n", mphf_bucket + offset[h0]);
	return (mphf_bucket + offset[h0]);	
}
Example #8
0
cmph_uint32 chd_ph_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
	register CMPH_HASH hl_type  = *(cmph_uint32 *)packed_mphf;
	register cmph_uint8 *hl_ptr = (cmph_uint8 *)(packed_mphf) + 4;
	
	register cmph_uint32 * ptr = (cmph_uint32 *)(hl_ptr + hash_state_packed_size(hl_type));
	register cmph_uint32 n = *ptr++;
	register cmph_uint32 nbuckets = *ptr++;
	cmph_uint32 hl[3];
		
	register cmph_uint32 disp,position;
	register cmph_uint32 probe0_num,probe1_num;
	register cmph_uint32 f,g,h;
	
	hash_vector_packed(hl_ptr, hl_type, key, keylen, hl);

	g = hl[0] % nbuckets;
	f = hl[1] % n;
	h = hl[2] % (n-1) + 1;
	
	disp = compressed_seq_query_packed(ptr, g);
	probe0_num = disp % n;
	probe1_num = disp/n;
	position = (cmph_uint32)((f + ((cmph_uint64 )h)*probe0_num + probe1_num) % n);
	return position;
}
Example #9
0
void chd_ph_pack(cmph_t *mphf, void *packed_mphf)
{
	chd_ph_data_t *data = (chd_ph_data_t *)mphf->data;
	cmph_uint8 * ptr = packed_mphf;

	// packing hl type
	CMPH_HASH hl_type = hash_get_type(data->hl);
	*((cmph_uint32 *) ptr) = hl_type;
	ptr += sizeof(cmph_uint32);

	// packing hl
	hash_state_pack(data->hl, ptr);
	ptr += hash_state_packed_size(hl_type);

	// packing n
	*((cmph_uint32 *) ptr) = data->n;
	ptr += sizeof(data->n);

	// packing nbuckets
	*((cmph_uint32 *) ptr) = data->nbuckets;
	ptr += sizeof(data->nbuckets);

	// packing cs
	compressed_seq_pack(data->cs, ptr);
	//ptr += compressed_seq_packed_size(data->cs);

}
Example #10
0
cmph_uint32 chd_ph_packed_size(cmph_t *mphf)
{
	register chd_ph_data_t *data = (chd_ph_data_t *)mphf->data;
	register CMPH_HASH hl_type = hash_get_type(data->hl); 
	register cmph_uint32 hash_state_pack_size =  hash_state_packed_size(hl_type);
	register cmph_uint32 cs_pack_size = compressed_seq_packed_size(data->cs);
	
	return (cmph_uint32)(sizeof(CMPH_ALGO) + hash_state_pack_size + cs_pack_size + 3*sizeof(cmph_uint32));

}
Example #11
0
/** \fn void fch_pack(cmph_t *mphf, void *packed_mphf);
 *  \brief Support the ability to pack a perfect hash function into a preallocated contiguous memory space pointed by packed_mphf.
 *  \param mphf pointer to the resulting mphf
 *  \param packed_mphf pointer to the contiguous memory area used to store the resulting mphf. The size of packed_mphf must be at least cmph_packed_size() 
 */
void fch_pack(cmph_t *mphf, void *packed_mphf)
{
	fch_data_t *data = (fch_data_t *)mphf->data;
	cmph_uint8 * ptr = packed_mphf;

	// packing h1 type
	CMPH_HASH h1_type = hash_get_type(data->h1);
    CMPH_HASH h2_type;
	*((cmph_uint32 *) ptr) = h1_type;
	ptr += sizeof(cmph_uint32);

	// packing h1
	hash_state_pack(data->h1, ptr);
	ptr += hash_state_packed_size(h1_type);

	// packing h2 type
	 h2_type = hash_get_type(data->h2);
	*((cmph_uint32 *) ptr) = h2_type;
	ptr += sizeof(cmph_uint32);

	// packing h2
	hash_state_pack(data->h2, ptr);
	ptr += hash_state_packed_size(h2_type);

	// packing m
	*((cmph_uint32 *) ptr) = data->m;
	ptr += sizeof(data->m);

	// packing b
	*((cmph_uint32 *) ptr) = data->b;
	ptr += sizeof(data->b);
	
	// packing p1
	*((cmph_uint64 *)ptr) = (cmph_uint64)data->p1; 
	ptr += sizeof(data->p1);

	// packing p2
	*((cmph_uint64 *)ptr) = (cmph_uint64)data->p2; 
	ptr += sizeof(data->p2);

	// packing g
	memcpy(ptr, data->g, sizeof(cmph_uint32)*(data->b));	
}
Example #12
0
/** cmph_uint8 bmz8_search(void *packed_mphf, const char *key, cmph_uint32 keylen);
 *  \brief Use the packed mphf to do a search.
 *  \param  packed_mphf pointer to the packed mphf
 *  \param key key to be hashed
 *  \param keylen key legth in bytes
 *  \return The mphf value
 */
cmph_uint8 bmz8_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
	register cmph_uint8 *h1_ptr = (cmph_uint8 *)packed_mphf;
	register CMPH_HASH h1_type  = (CMPH_HASH)(*((cmph_uint32 *)h1_ptr));
	h1_ptr += 4;

	register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
	register CMPH_HASH h2_type  = (CMPH_HASH)(*((cmph_uint32 *)h2_ptr));
	h2_ptr += 4;

	register cmph_uint8 *g_ptr = h2_ptr + hash_state_packed_size(h2_type);

	register cmph_uint8 n = *g_ptr++;

	register cmph_uint8 h1 = (cmph_uint8)(hash_packed(h1_ptr, h1_type, key, keylen) % n);
	register cmph_uint8 h2 = (cmph_uint8)(hash_packed(h2_ptr, h2_type, key, keylen) % n);
	DEBUGP("key: %s h1: %u h2: %u\n", key, h1, h2);
	if (h1 == h2 && ++h2 > n) h2 = 0;
	return (cmph_uint8)(g_ptr[h1] + g_ptr[h2]);
}
Example #13
0
/** cmph_uint32 chm_search(void *packed_mphf, const char *key, cmph_uint32 keylen);
 *  \brief Use the packed mphf to do a search.
 *  \param  packed_mphf pointer to the packed mphf
 *  \param key key to be hashed
 *  \param keylen key legth in bytes
 *  \return The mphf value
 */
cmph_uint32 chm_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen)
{
    register cmph_uint8 *h1_ptr = packed_mphf;
    register CMPH_HASH h1_type  = *((cmph_uint32 *)h1_ptr);
    h1_ptr += 4;

    register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
    register CMPH_HASH h2_type  = *((cmph_uint32 *)h2_ptr);
    h2_ptr += 4;

    register cmph_uint32 *g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type));

    register cmph_uint32 n = *g_ptr++;
    register cmph_uint32 m = *g_ptr++;

    register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n;
    register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n;
    DEBUGP("key: %s h1: %u h2: %u\n", key, h1, h2);
    if (h1 == h2 && ++h2 >= n) h2 = 0;
    DEBUGP("key: %s g[h1]: %u g[h2]: %u edges: %u\n", key, g_ptr[h1], g_ptr[h2], m);
    return (g_ptr[h1] + g_ptr[h2]) % m;
}
Example #14
0
/** \fn cmph_uint32 brz_packed_size(cmph_t *mphf);
 *  \brief Return the amount of space needed to pack mphf.
 *  \param mphf pointer to a mphf
 *  \return the size of the packed function or zero for failures
 */ 
cmph_uint32 brz_packed_size(cmph_t *mphf)
{
	cmph_uint32 i;
	cmph_uint32 size = 0;
	brz_data_t *data = (brz_data_t *)mphf->data;
	CMPH_HASH h0_type = hash_get_type(data->h0); 
	CMPH_HASH h1_type = hash_get_type(data->h1[0]); 
	CMPH_HASH h2_type = hash_get_type(data->h2[0]);
	size = (cmph_uint32)(2*sizeof(CMPH_ALGO) + 3*sizeof(CMPH_HASH) + hash_state_packed_size(h0_type) + sizeof(cmph_uint32) + 
			sizeof(double) + sizeof(cmph_uint8)*data->k + sizeof(cmph_uint32)*data->k);
	// pointers to g_is
	#if defined (__ia64) || defined (__x86_64__)
		size +=  (cmph_uint32) sizeof(cmph_uint64)*data->k;
	#else
		size +=  (cmph_uint32) sizeof(cmph_uint32)*data->k;
	#endif
	
	size += hash_state_packed_size(h1_type) * data->k;
	size += hash_state_packed_size(h2_type) * data->k;
	
	cmph_uint32 n = 0;
	for(i = 0; i < data->k; i++)
	{
   		switch(data->algo)
   		{
   			case CMPH_FCH:
   				n = fch_calc_b(data->c, data->size[i]);
   				break;
   			case CMPH_BMZ8:
   				n = (cmph_uint32)ceil(data->c * data->size[i]);
   				break;
   			default: assert(0);
   		}
		size += n;	
	}
	return size;
}
Example #15
0
/** \fn void brz_pack(cmph_t *mphf, void *packed_mphf);
 *  \brief Support the ability to pack a perfect hash function into a preallocated contiguous memory space pointed by packed_mphf.
 *  \param mphf pointer to the resulting mphf
 *  \param packed_mphf pointer to the contiguous memory area used to store the resulting mphf. The size of packed_mphf must be at least cmph_packed_size() 
 */
void brz_pack(cmph_t *mphf, void *packed_mphf)
{
	brz_data_t *data = (brz_data_t *)mphf->data;
	cmph_uint8 * ptr = packed_mphf;
	cmph_uint32 i,n;
	
	// packing internal algo type
	memcpy(ptr, &(data->algo), sizeof(data->algo));
	ptr += sizeof(data->algo);

	// packing h0 type
	CMPH_HASH h0_type = hash_get_type(data->h0); 
	memcpy(ptr, &h0_type, sizeof(h0_type));
	ptr += sizeof(h0_type);

	// packing h0
	hash_state_pack(data->h0, ptr);
	ptr += hash_state_packed_size(h0_type);
	
	// packing k
	memcpy(ptr, &(data->k), sizeof(data->k));
	ptr += sizeof(data->k);

	// packing c
	*((cmph_uint64 *)ptr) = (cmph_uint64)data->c; 
	ptr += sizeof(data->c);

	// packing h1 type
	CMPH_HASH h1_type = hash_get_type(data->h1[0]); 
	memcpy(ptr, &h1_type, sizeof(h1_type));
	ptr += sizeof(h1_type);

	// packing h2 type
	CMPH_HASH h2_type = hash_get_type(data->h2[0]); 
	memcpy(ptr, &h2_type, sizeof(h2_type));
	ptr += sizeof(h2_type);

	// packing size
	memcpy(ptr, data->size, sizeof(cmph_uint8)*data->k);	
	ptr += data->k;
	
	// packing offset
	memcpy(ptr, data->offset, sizeof(cmph_uint32)*data->k);	
	ptr += sizeof(cmph_uint32)*data->k;
	
	#if defined (__ia64) || defined (__x86_64__)
		cmph_uint64 * g_is_ptr = (cmph_uint64 *)ptr;
	#else
		cmph_uint32 * g_is_ptr = (cmph_uint32 *)ptr;
	#endif
	
	cmph_uint8 * g_i = (cmph_uint8 *) (g_is_ptr + data->k);
	
	for(i = 0; i < data->k; i++)
	{
		#if defined (__ia64) || defined (__x86_64__)
			*g_is_ptr++ = (cmph_uint64)g_i;
		#else
			*g_is_ptr++ = (cmph_uint32)g_i;
		#endif
		// packing h1[i]
		hash_state_pack(data->h1[i], g_i);
		g_i += hash_state_packed_size(h1_type);
		
		// packing h2[i]
		hash_state_pack(data->h2[i], g_i);
		g_i += hash_state_packed_size(h2_type);

		// packing g_i
		switch(data->algo)
		{
			case CMPH_FCH:
				n = fch_calc_b(data->c, data->size[i]);
				break;
			case CMPH_BMZ8:
				n = (cmph_uint32)ceil(data->c * data->size[i]);
				break;
			default: assert(0);
		}
		memcpy(g_i, data->g[i], sizeof(cmph_uint8)*n);	
		g_i += n;
		
	}

}