diff options
author | Marvin Borner | 2023-05-21 18:55:31 +0200 |
---|---|---|
committer | Marvin Borner | 2023-05-21 20:29:25 +0200 |
commit | 05d9c29717f7ae31dfad9230d469af0fa7f0c761 (patch) | |
tree | a7e6547c4d3fc346e853d455f5c1a288505abc31 /src/build.c | |
parent | 7ebabbb0022bce1cd6c05db583acb20d8659a356 (diff) |
Applied variadic index length technique
Diffstat (limited to 'src/build.c')
-rw-r--r-- | src/build.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/build.c b/src/build.c index e396407..d90b714 100644 --- a/src/build.c +++ b/src/build.c @@ -46,9 +46,28 @@ static void rec_write_bblc(struct tree *tree, FILE *file, char *byte, int *bit) write_bit(1, file, byte, bit); write_bit(1, file, byte, bit); - // TODO: The bit-order of encoded shorts is kinda arbitrary - short ref = tree->u.ref.table_index; - for (int i = 0; i < 16; i++) + int ref = tree->u.ref.table_index; + int bits = 0; + + // write index length bit prefixes + if (ref < 2 << 7) { + bits = 8; + write_bit(0, file, byte, bit); + write_bit(0, file, byte, bit); + } else if (ref < 2 << 15) { + bits = 16; + write_bit(0, file, byte, bit); + write_bit(1, file, byte, bit); + } else if (ref < 2 << 31) { + bits = 32; + write_bit(1, file, byte, bit); + write_bit(0, file, byte, bit); + } else if (ref < 2 << 63) { + bits = 64; // i wanna see that program lol + write_bit(1, file, byte, bit); + write_bit(1, file, byte, bit); + } + for (int i = 0; i < bits; i++) write_bit((ref >> i) & 1, file, byte, bit); break; default: |