Commit f47bf905 by Rudolf

On single parent use case (single char), just store the no. of chars

This saves more than huffman encoding. Note the header is still stored as usual.
parent a68e36c6
Showing with 10 additions and 5 deletions
......@@ -194,6 +194,13 @@ int encode_tree(struct BIT_BUFFER *bitbuf, struct tree *parent, char *buf,
{
printf("Bit pos at %d %d\n", ftell(bitbuf->fp), bitbuf->pos);
/* It makes much more sense to write the count when there is only one
* char. */
if (!parent->left && !parent->right) {
bb_writebyte(bitbuf, parent->freq);
return 0;
}
int maxheight = get_max_height(parent) - 1;
int *pathbuf = calloc(maxheight, sizeof(int));
......@@ -220,16 +227,14 @@ static int read_entries(struct BIT_BUFFER *bitbuf, FILE *out,
/* If we compress only one letter, the root node is the node containing
* character. So this needs special care. */
#if 0
if (!parent->left && !parent->right) {
while (ftell(bitbuf->fp) != lastbyte && bitbuf->pos + throwaways < 8) {
bit = bb_read(bitbuf, 1);
free(bit);
int *count = bb_readbyte(bitbuf);
for (int i = 0; i < *count; i++) {
fwrite(&parent->ch, 1, 1, out);
}
free(count);
return 0;
}
#endif
while ((bit = bb_read(bitbuf, 1)) != NULL) {
printf("Reading bit %d\n", *bit);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment