Move next token to huffman tree lib
This commit is contained in:
parent
f778d01d74
commit
1ae8e5f050
4 changed files with 29 additions and 27 deletions
|
|
@ -8,6 +8,5 @@
|
||||||
|
|
||||||
bool detect_overlaps(char* filename);
|
bool detect_overlaps(char* filename);
|
||||||
int get_uncompressed_size(zip* in);
|
int get_uncompressed_size(zip* in);
|
||||||
int next_token(bitstream* bs, tree t);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -22,8 +22,11 @@ typedef struct tree
|
||||||
|
|
||||||
unsigned int* sort(unsigned char* ints, int size);
|
unsigned int* sort(unsigned char* ints, int size);
|
||||||
void print_huffman_tree(tree t);
|
void print_huffman_tree(tree t);
|
||||||
|
|
||||||
tree build_tree(char* bit_lengths, int size);
|
tree build_tree(char* bit_lengths, int size);
|
||||||
tree build_default_tree();
|
tree build_default_tree();
|
||||||
tree build_default_dist_tree();
|
tree build_default_dist_tree();
|
||||||
|
|
||||||
|
int next_token(bitstream* bs, tree t);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -16,28 +16,3 @@ int get_uncompressed_size(zip* in)
|
||||||
|
|
||||||
return size;
|
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;
|
|
||||||
}
|
|
||||||
|
|
@ -106,3 +106,28 @@ void print_huffman_tree(tree t)
|
||||||
printf("\n");
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue