예제 #1
0
static void
do_pack(const void *in, size_t in_len, size_t buf_len,
        size_t offset, size_t fp_len, Byte options) {
  size_t buflen = bmz_pack_buflen(in_len), out_len = buflen;
  size_t worklen = bmz_pack_worklen(in_len, fp_len);
  int ret, bm_only = (options & BMZ_O_BM_ONLY) || s_bm_dump;
  Byte *out, *work_mem;

  if (bm_only) {
    out_len = in_len + 1;

    if (buf_len > in_len + worklen) {
      out = (Byte *)in + in_len;
      work_mem = out + out_len;
    }
    else {
      out = malloc(worklen); /* bmz_pack_worklen includes out_len for bm */

      if (!out)
        DIE("error allocating %lu bytes memory", (Lu)worklen);

      work_mem = out + out_len;
    }
    /* calling internal API need to align work memory */
    work_mem = BMZ_ALIGN(work_mem, 8);
  }
  else if (buf_len > buflen + worklen) {
    work_mem = (Byte *)in + buflen;
    out = (Byte *)in; /* inplace */
  }
  else {
    out = malloc(buflen + worklen);

    if (!out)
      DIE("error allocating %lu bytes memory", (Lu)buflen + worklen);

    work_mem = out + buflen;
  }

  if (bm_only) {
    ret = bmz_bm_pack_mask(in, in_len, out, &out_len, offset, fp_len,
                           work_mem, 257);
    if (ret != BMZ_E_OK)
      DIE("error encoding bm output (error %d)", ret);

    if (s_bm_dump) {
      if ((ret = bmz_bm_dump(out, out_len)) != BMZ_E_OK)
        WARN("error dumping bm encoding (ret=%d)", ret);

      return;
    }
  }
  else if ((ret = bmz_pack(in, in_len, out, &out_len, offset, fp_len,
                           (s_bm_hash << 24), work_mem))
           != BMZ_E_OK) {
    DIE("error compressing input (error %d)", ret);
  }
  write_bmz_header(1, in_len, bmz_checksum(out, out_len), options);
  write(1, out, out_len);
}
예제 #2
0
파일: cmph.c 프로젝트: dguthrie/ShefLM
/** \fn void cmph_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 cmph_pack(cmph_t *mphf, void *packed_mphf)
{
	// packing algorithm type to be used in cmph.c
	cmph_uint32 * ptr = (cmph_uint32 *) packed_mphf; 
	*ptr++ = mphf->algo;
	DEBUGP("mphf->algo = %u\n", mphf->algo);
	switch(mphf->algo)
	{
		case CMPH_CHM:
			chm_pack(mphf, ptr);
			break;
		case CMPH_BMZ: /* included -- Fabiano */
			bmz_pack(mphf, ptr);
			break;
		case CMPH_BMZ8: /* included -- Fabiano */
			bmz8_pack(mphf, ptr);
			break;
		case CMPH_BRZ: /* included -- Fabiano */
			brz_pack(mphf, ptr);
			break;
		case CMPH_FCH: /* included -- Fabiano */
			fch_pack(mphf, ptr);
			break;
		case CMPH_BDZ: /* included -- Fabiano */
			bdz_pack(mphf, ptr);
			break;
		case CMPH_BDZ_PH: /* included -- Fabiano */
			bdz_ph_pack(mphf, ptr);
			break;
		case CMPH_CHD_PH: /* included -- Fabiano */
			chd_ph_pack(mphf, ptr);
			break;
		case CMPH_CHD: /* included -- Fabiano */
			chd_pack(mphf, ptr);
			break;
		default: 
			assert(0);
	}
	return;
}