61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
|
#include <iostream>
|
||
|
|
||
|
#include "HuffmanStream.h"
|
||
|
|
||
|
|
||
|
void testHuffmanCodeLengthTable()
|
||
|
{
|
||
|
HuffmanCodeLengthTable table;
|
||
|
|
||
|
std::vector<std::pair<unsigned, unsigned char> > mappings {{144, 8}, {112, 9}, {24, 7}, {8 ,8}};
|
||
|
std::vector<unsigned char> code_length_sequence;
|
||
|
for(const auto& entry : mappings)
|
||
|
{
|
||
|
for(unsigned idx=0;idx<entry.first;idx++)
|
||
|
{
|
||
|
code_length_sequence.push_back(entry.second);
|
||
|
}
|
||
|
}
|
||
|
table.setInputLengthSequence(code_length_sequence, false);
|
||
|
|
||
|
table.buildCompressedLengthSequence();
|
||
|
|
||
|
auto compressed_sequence = table.getCompressedLengthSequence();
|
||
|
for (auto entry : compressed_sequence)
|
||
|
{
|
||
|
std::cout << "Count " << entry.first << " extra bits " << entry.second << std::endl;
|
||
|
}
|
||
|
|
||
|
auto compressed_lengths = table.getCompressedLengthCounts();
|
||
|
for(unsigned idx = 0; idx<compressed_lengths.size(); idx++)
|
||
|
{
|
||
|
std::cout << "Slot " << idx << " length " << compressed_lengths[idx] << std::endl;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
testHuffmanCodeLengthTable();
|
||
|
//HuffmanStream stream(nullptr, nullptr);
|
||
|
|
||
|
//stream.setCodeLengthAlphabetLengths({3, 3, 3, 3, 3, 2, 4, 4});
|
||
|
|
||
|
//stream.setCodeLengthAlphabetLengths({2, 2, 3, 3, 3, 3});
|
||
|
|
||
|
//stream.buildCodeLengthMapping();
|
||
|
|
||
|
std::cout << "*******" << std::endl;
|
||
|
//stream.setCodeLengthAlphabetLengths({4, 0, 6, 7, 3, 2, 4, 2, 7, 4, 6, 3, 0, 6});
|
||
|
|
||
|
//stream.buildCodeLengthMapping();
|
||
|
|
||
|
//const auto mapping = stream.getCodeLengthMapping();
|
||
|
|
||
|
//stream.generateFixedCodeMapping();
|
||
|
|
||
|
|
||
|
return 0;
|
||
|
}
|