Exemple #1
0
int hitbuffer_inc(hitbuffer *hb, Z32 *hit) {
	hb->freq += 1LLU; //LLU for 64-bit.  OSX 10.5 is VERY finicky about this.
	int result;
	if (hb->freq < PHILO_INDEX_CUTOFF) {
		add_to_dir(hb, hit, 1);
//		fprintf(stderr, "added hit for %s...\n", hb->word);
	}
	else if (hb->freq == PHILO_INDEX_CUTOFF) {
			//when the frequency reaches 10, we start using a block-header layout.
			//each "hit" in the directory corresponds to a large, compressed block of hits.
			//by comparing the directory headers to the query, the search engine skips blocks if possible.

			result = add_to_block(hb,&(hb->dir[1*hb->db->dbspec->fields]),PHILO_INDEX_CUTOFF - 2);
			if (result == PHILO_BLOCK_FULL) {
				fprintf(stderr, "you can't fit PHILO_INDEX_CUTOFF hits into a block!  adjust your block size, or your index cutoff.\n");	
			}

			hb->dir_length = 1LLU;
			hb->type = 1;
			result = add_to_block(hb,hit,1);
//			fprintf(stderr, "clearing dir.  started new block for %s...\n", hb->word);
	}
	if (hb->freq > PHILO_INDEX_CUTOFF) {
		result = add_to_block(hb,hit,1);
		if (result == PHILO_BLOCK_FULL) {
			// IF the block add failed,
			write_blk(hb); //write the full block out, start a new one,
			add_to_dir(hb,hit,1); //then push the current hit onto the directory.
//			fprintf(stderr, "started new block for %s...\n", hb->word);
		}
	}		
	return 0;
}
Exemple #2
0
/******************************************************************************
**  huffman_encode

**  --------------------------------------------------------------------------
**  Quantize and Encode a 8x8 DCT block by JPEG Huffman lossless coding.
**  This function writes encoded bit-stream into bit-buffer.
**  
**  ARGUMENTS:
**      ctx     - pointer to encoder context;
**      data    - pointer to 8x8 DCT block;
**
**  RETURN: -
******************************************************************************/
void huffman_encode(huffman_t *const ctx, const short data[], unsigned block_num)
{
	unsigned magn, bits;
	unsigned zerorun, i;
	short    diff;
	short    dc = quantize(data[0], ctx->qtable[0]);

	// WARNING: in order to everything to work correctly
	// the get_DC_value must be called before the block_start
	// otherwise it returns a wrong DC value in case of megablocks
	// (the block_start reset the force_marker variable, which is
	// used by get_DC_value
	diff = get_DC_value(dc, block_num);
	block_start(block_num);

	bits = huffman_bits(diff);
	magn = huffman_magnitude(diff);

	add_to_block(ctx->hdcbit[magn], ctx->hdclen[magn]);
	add_to_block(bits, magn);
	
	for (zerorun = 0, i = 1; i < 64; i++)
	{
		const short ac = quantize(data[zig[i]], ctx->qtable[zig[i]]);

		if (ac) {
			while (zerorun >= 16) {
				zerorun -= 16;
				// ZRL
				add_to_block(ctx->hacbit[15][0], ctx->haclen[15][0]);
			}

			bits = huffman_bits(ac);
			magn = huffman_magnitude(ac);
			add_to_block(ctx->hacbit[zerorun][magn], ctx->haclen[zerorun][magn]);
			add_to_block(bits, magn);

			zerorun = 0;
		}
		else zerorun++;
	}

	if (zerorun) { // EOB - End Of Block
		add_to_block(ctx->hacbit[0][0], ctx->haclen[0][0]);
	}
	block_end(&bitbuf);
}