Commit 8d8a93df by Rudolf

Fix 0 char handling when encoding

The 0 char was encoded as just 0 (as the left->ch == 0 when it is a branch).
Fix is to first compare right index, and if it doesn't match then use last left.
parent f2296313
Showing with 12 additions and 0 deletions
...@@ -102,6 +102,7 @@ static int write_entry(struct BIT_BUFFER *bitbuf, struct tree *parent, ...@@ -102,6 +102,7 @@ static int write_entry(struct BIT_BUFFER *bitbuf, struct tree *parent,
left = parent->left; left = parent->left;
right = parent->right; right = parent->right;
if (c != 0) {
if (left->ch == c) { if (left->ch == c) {
int bit = 0; int bit = 0;
bb_write(bitbuf, &bit, 1); bb_write(bitbuf, &bit, 1);
...@@ -111,6 +112,17 @@ static int write_entry(struct BIT_BUFFER *bitbuf, struct tree *parent, ...@@ -111,6 +112,17 @@ static int write_entry(struct BIT_BUFFER *bitbuf, struct tree *parent,
bb_write(bitbuf, &bit, 1); bb_write(bitbuf, &bit, 1);
break; break;
} }
} else {
if (left->left == NULL) {
int bit = 0;
bb_write(bitbuf, &bit, 1);
break;
} else if (right->ch == c) {
int bit = 1;
bb_write(bitbuf, &bit, 1);
break;
}
}
int bit = 0; int bit = 0;
bb_write(bitbuf, &bit, 1); bb_write(bitbuf, &bit, 1);
......
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