Read next token
This commit is contained in:
parent
2ff199072e
commit
48aba6093b
2 changed files with 29 additions and 1 deletions
|
|
@ -1,10 +1,13 @@
|
|||
#ifndef LIBMINEZIPER_H
|
||||
#define LIBMINEZIPER_H
|
||||
|
||||
#include "libmineziper_zip.h"
|
||||
#include <stdbool.h>
|
||||
#include "libmineziper_bitstream.h"
|
||||
#include "libmineziper_huffman_tree.h"
|
||||
#include "libmineziper_zip.h"
|
||||
|
||||
bool detect_overlaps(char* filename);
|
||||
int get_uncompressed_size(zip* in);
|
||||
int next_token(bitstream* bs, tree t);
|
||||
|
||||
#endif
|
||||
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue