Пример #1
0
void fch_load(FILE *f, cmph_t *mphf)
{
	char *buf = NULL;
	cmph_uint32 buflen;
	register size_t nbytes;
	fch_data_t *fch = (fch_data_t *)malloc(sizeof(fch_data_t));

	//DEBUGP("Loading fch mphf\n");
	mphf->data = fch;
	//DEBUGP("Reading h1\n");
	fch->h1 = NULL;
	nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
	//DEBUGP("Hash state of h1 has %u bytes\n", buflen);
	buf = (char *)malloc((size_t)buflen);
	nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
	fch->h1 = hash_state_load(buf, buflen);
	free(buf);
	
	//DEBUGP("Loading fch mphf\n");
	mphf->data = fch;
	//DEBUGP("Reading h2\n");
	fch->h2 = NULL;
	nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
	//DEBUGP("Hash state of h2 has %u bytes\n", buflen);
	buf = (char *)malloc((size_t)buflen);
	nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
	fch->h2 = hash_state_load(buf, buflen);
	free(buf);
	
	
	//DEBUGP("Reading m and n\n");
	nbytes = fread(&(fch->m), sizeof(cmph_uint32), (size_t)1, f);
	nbytes = fread(&(fch->c), sizeof(double), (size_t)1, f);
	nbytes = fread(&(fch->b), sizeof(cmph_uint32), (size_t)1, f);
	nbytes = fread(&(fch->p1), sizeof(double), (size_t)1, f);
	nbytes = fread(&(fch->p2), sizeof(double), (size_t)1, f);

	fch->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*fch->b);
	nbytes = fread(fch->g, fch->b*sizeof(cmph_uint32), (size_t)1, f);
        if (nbytes == 0 && ferror(f)) {
          fprintf(stderr, "ERROR: %s\n", strerror(errno));
          return;
        }
	#ifdef DEBUG
	cmph_uint32 i;
	fprintf(stderr, "G: ");
	for (i = 0; i < fch->b; ++i) fprintf(stderr, "%u ", fch->g[i]);
	fprintf(stderr, "\n");
	#endif
	return;
}
Пример #2
0
void chd_ph_load(FILE *fd, cmph_t *mphf)
{
	char *buf = NULL;
	cmph_uint32 buflen;
	register size_t nbytes;
	chd_ph_data_t *chd_ph = (chd_ph_data_t *)malloc(sizeof(chd_ph_data_t));

	DEBUGP("Loading chd_ph mphf\n");
	mphf->data = chd_ph;

	nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
	DEBUGP("Hash state has %u bytes\n", buflen);
	buf = (char *)malloc((size_t)buflen);
	nbytes = fread(buf, (size_t)buflen, (size_t)1, fd);
	chd_ph->hl = hash_state_load(buf, buflen);
	free(buf);
	
	nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, fd);
	DEBUGP("Compressed sequence structure has %u bytes\n", buflen);
	buf = (char *)malloc((size_t)buflen);
	nbytes = fread(buf, (size_t)buflen, (size_t)1, fd);
	chd_ph->cs = (compressed_seq_t *) calloc(1, sizeof(compressed_seq_t)); 
	compressed_seq_load(chd_ph->cs, buf, buflen);
	free(buf);
	
	// loading n and nbuckets
	DEBUGP("Reading n and nbuckets\n");
	nbytes = fread(&(chd_ph->n), sizeof(cmph_uint32), (size_t)1, fd);	
	nbytes = fread(&(chd_ph->nbuckets), sizeof(cmph_uint32), (size_t)1, fd);	
	if (nbytes == 0 && ferror(fd)) {
          fprintf(stderr, "ERROR: %s\n", strerror(errno));
        }

}
Пример #3
0
void bmz8_load(FILE *f, cmph_t *mphf)
{
	cmph_uint8 nhashes;
	char *buf = NULL;
	cmph_uint32 buflen;
	cmph_uint8 i;
	register size_t nbytes;
	bmz8_data_t *bmz8 = (bmz8_data_t *)malloc(sizeof(bmz8_data_t));

	DEBUGP("Loading bmz8 mphf\n");
	mphf->data = bmz8;
	nbytes = fread(&nhashes, sizeof(cmph_uint8), (size_t)1, f);
	bmz8->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(size_t)(nhashes + 1));
	bmz8->hashes[nhashes] = NULL;
	DEBUGP("Reading %u hashes\n", nhashes);
	for (i = 0; i < nhashes; ++i)
	{
		hash_state_t *state = NULL;
		nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
		DEBUGP("Hash state has %u bytes\n", buflen);
		buf = (char *)malloc((size_t)buflen);
		nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
		state = hash_state_load(buf, buflen);
		bmz8->hashes[i] = state;
		free(buf);
	}

	DEBUGP("Reading m and n\n");
	nbytes = fread(&(bmz8->n), sizeof(cmph_uint8), (size_t)1, f);
	nbytes = fread(&(bmz8->m), sizeof(cmph_uint8), (size_t)1, f);

	bmz8->g = (cmph_uint8 *)malloc(sizeof(cmph_uint8)*bmz8->n);
	nbytes = fread(bmz8->g, bmz8->n*sizeof(cmph_uint8), (size_t)1, f);
	#ifdef DEBUG
	fprintf(stderr, "G: ");
	for (i = 0; i < bmz8->n; ++i) fprintf(stderr, "%u ", bmz8->g[i]);
	fprintf(stderr, "\n");
	#endif

	if ( nbytes == 0 )
    {
        ;
    }

	return;
}
Пример #4
0
void bmz_load(FILE *f, cmph_t *mphf)
{
	cmph_uint32 nhashes;
	char *buf = NULL;
	cmph_uint32 buflen;
	cmph_uint32 i;
	bmz_data_t *bmz = (bmz_data_t *)malloc(sizeof(bmz_data_t));
	register size_t nbytes;
	DEBUGP("Loading bmz mphf\n");
	mphf->data = bmz;
	nbytes = fread(&nhashes, sizeof(cmph_uint32), (size_t)1, f);
	bmz->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
	bmz->hashes[nhashes] = NULL;
	DEBUGP("Reading %u hashes\n", nhashes);
	for (i = 0; i < nhashes; ++i)
	{
		hash_state_t *state = NULL;
		nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
		DEBUGP("Hash state has %u bytes\n", buflen);
		buf = (char *)malloc((size_t)buflen);
		nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
		state = hash_state_load(buf, buflen);
		bmz->hashes[i] = state;
		free(buf);
	}

	DEBUGP("Reading m and n\n");
	nbytes = fread(&(bmz->n), sizeof(cmph_uint32), (size_t)1, f);	
	nbytes = fread(&(bmz->m), sizeof(cmph_uint32), (size_t)1, f);	

	bmz->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*bmz->n);
	nbytes = fread(bmz->g, bmz->n*sizeof(cmph_uint32), (size_t)1, f);
	if (nbytes == 0 && ferror(f)) {
          fprintf(stderr, "ERROR: %s\n", strerror(errno));
          return;
        }

	#ifdef DEBUG
	fprintf(stderr, "G: ");
	for (i = 0; i < bmz->n; ++i) fprintf(stderr, "%u ", bmz->g[i]);
	fprintf(stderr, "\n");
	#endif
	return;
}
Пример #5
0
void chm_load(FILE *f, cmph_t *mphf)
{
    cmph_uint32 nhashes;
    char *buf = NULL;
    cmph_uint32 buflen;
    cmph_uint32 i;
    chm_data_t *chm = (chm_data_t *)malloc(sizeof(chm_data_t));
    register size_t nbytes;
    DEBUGP("Loading chm mphf\n");
    mphf->data = chm;
    nbytes = fread(&nhashes, sizeof(cmph_uint32), (size_t)1, f);
    chm->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
    chm->hashes[nhashes] = NULL;
    DEBUGP("Reading %u hashes\n", nhashes);
    for (i = 0; i < nhashes; ++i)
    {
        hash_state_t *state = NULL;
        nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
        DEBUGP("Hash state has %u bytes\n", buflen);
        buf = (char *)malloc((size_t)buflen);
        nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
        state = hash_state_load(buf, buflen);
        chm->hashes[i] = state;
        free(buf);
    }

    DEBUGP("Reading m and n\n");
    nbytes = fread(&(chm->n), sizeof(cmph_uint32), (size_t)1, f);
    nbytes = fread(&(chm->m), sizeof(cmph_uint32), (size_t)1, f);

    chm->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*chm->n);
    nbytes = fread(chm->g, chm->n*sizeof(cmph_uint32), (size_t)1, f);
#ifdef DEBUG
    fprintf(stderr, "G: ");
    for (i = 0; i < chm->n; ++i) fprintf(stderr, "%u ", chm->g[i]);
    fprintf(stderr, "\n");
#endif
    return;
}
Пример #6
0
void brz_load(FILE *f, cmph_t *mphf)
{
	char *buf = NULL;
	cmph_uint32 buflen;
	register size_t nbytes;
	cmph_uint32 i, n;
	brz_data_t *brz = (brz_data_t *)malloc(sizeof(brz_data_t));

	DEBUGP("Loading brz mphf\n");
	mphf->data = brz;
	nbytes = fread(&(brz->c), sizeof(double), (size_t)1, f);
	nbytes = fread(&(brz->algo), sizeof(brz->algo), (size_t)1, f); // Reading algo.
	nbytes = fread(&(brz->k), sizeof(cmph_uint32), (size_t)1, f);
	brz->size   = (cmph_uint8 *) malloc(sizeof(cmph_uint8)*brz->k);
	nbytes = fread(brz->size, sizeof(cmph_uint8)*(brz->k), (size_t)1, f);	
	brz->h1 = (hash_state_t **)malloc(sizeof(hash_state_t *)*brz->k);
	brz->h2 = (hash_state_t **)malloc(sizeof(hash_state_t *)*brz->k);
	brz->g  = (cmph_uint8 **)  calloc((size_t)brz->k, sizeof(cmph_uint8 *));
	DEBUGP("Reading c = %f   k = %u   algo = %u \n", brz->c, brz->k, brz->algo);
	//loading h_i1, h_i2 and g_i.
	for(i = 0; i < brz->k; i++)
	{
		// h1
		nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
		DEBUGP("Hash state 1 has %u bytes\n", buflen);
		buf = (char *)malloc((size_t)buflen);
		nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
		brz->h1[i] = hash_state_load(buf, buflen);
		free(buf);
		//h2
		nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
		DEBUGP("Hash state 2 has %u bytes\n", buflen);
		buf = (char *)malloc((size_t)buflen);
		nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
		brz->h2[i] = hash_state_load(buf, buflen);
		free(buf);
		switch(brz->algo)
		{
			case CMPH_FCH:
				n = fch_calc_b(brz->c, brz->size[i]);
				break;
			case CMPH_BMZ8:
				n = (cmph_uint32)ceil(brz->c * brz->size[i]);
				break;
			default: assert(0);
		}
		DEBUGP("g_i has %u bytes\n", n);
		brz->g[i] = (cmph_uint8 *)calloc((size_t)n, sizeof(cmph_uint8));
		nbytes = fread(brz->g[i], sizeof(cmph_uint8)*n, (size_t)1, f);
	}
	//loading h0
	nbytes = fread(&buflen, sizeof(cmph_uint32), (size_t)1, f);
	DEBUGP("Hash state has %u bytes\n", buflen);
	buf = (char *)malloc((size_t)buflen);
	nbytes = fread(buf, (size_t)buflen, (size_t)1, f);
	brz->h0 = hash_state_load(buf, buflen);
	free(buf);

	//loading c, m, and the vector offset.	
	nbytes = fread(&(brz->m), sizeof(cmph_uint32), (size_t)1, f);
	brz->offset = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*brz->k);
	nbytes = fread(brz->offset, sizeof(cmph_uint32)*(brz->k), (size_t)1, f);
	return;
}