Read next token

This commit is contained in:
atxr 2024-02-20 12:33:44 +01:00
parent 2ff199072e
commit 48aba6093b
2 changed files with 29 additions and 1 deletions

View file

@ -15,4 +15,29 @@ int get_uncompressed_size(zip* in)
}
return size;
}
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;
}