Move next token to huffman tree lib

This commit is contained in:
atxr 2024-02-20 15:36:46 +01:00
parent f778d01d74
commit 1ae8e5f050
4 changed files with 29 additions and 27 deletions

View file

@ -106,3 +106,28 @@ void print_huffman_tree(tree t)
printf("\n");
}
}
int next_token(bitstream* bs, tree t)
{
// TODO handle if tmin is null elsewhere
int init = 0;
if (t.min > 0)
{
init = t.min - 1;
}
unsigned int base = get_bits(bs, init);
for (int k = t.min; k <= t.max; k++)
{
base += get_bits(bs, 1) << (k - 1);
for (int i = 0; i < t.size; i++)
{
if (t.leaves[i].length == k && t.leaves[i].code == base)
return t.leaves[i].litteral;
}
}
return -1;
}