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 20 additions and 8 deletions
......@@ -102,14 +102,26 @@ static int write_entry(struct BIT_BUFFER *bitbuf, struct tree *parent,
left = parent->left;
right = parent->right;
if (left->ch == c) {
int bit = 0;
bb_write(bitbuf, &bit, 1);
break;
} else if (right->ch == c) {
int bit = 1;
bb_write(bitbuf, &bit, 1);
break;
if (c != 0) {
if (left->ch == c) {
int bit = 0;
bb_write(bitbuf, &bit, 1);
break;
} else if (right->ch == c) {
int bit = 1;
bb_write(bitbuf, &bit, 1);
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;
......
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