Work on dynamic huffman coding.

This commit is contained in:
James Grogan 2022-11-28 18:05:39 +00:00
parent 7f5009fb5e
commit a6e31c8d39
16 changed files with 456 additions and 95 deletions

View file

@ -26,9 +26,9 @@ unsigned char ByteUtils::getByteN(uint32_t input, unsigned n)
return (input << 8*n) >> 24;
}
unsigned char ByteUtils::mirror(unsigned char byte, unsigned length)
uint32_t ByteUtils::mirror(uint32_t byte, unsigned length)
{
unsigned char ret{0};
uint32_t ret{0};
for(unsigned idx=0; idx<length; idx++)
{
if (getBitN(byte, length - 1 - idx))
@ -121,31 +121,25 @@ unsigned char ByteUtils::getFromString(const std::string& string)
std::string ByteUtils::toString(uint32_t input, unsigned length)
{
std::string ret;
std::string working;
for(unsigned idx=0; idx<length; idx++)
if (length > 8)
{
if (idx > 0 && idx % 8 == 0)
unsigned overshoot = length - 8;
for(unsigned idx=0; idx<overshoot; idx++)
{
if (ret.empty())
{
ret = working;
}
else
{
ret = working + '-' + ret;
}
working = "";
ret += getBitN(input, length - 1 - idx) ? '1' : '0';
}
ret += "-";
for(unsigned idx=0; idx<8; idx++)
{
ret += getBitN(input, 7 - idx) ? '1' : '0';
}
working += getBitN(input, 7 - idx) ? '1' : '0';
}
if (length <= 8)
else
{
ret = working;
}
else if(!working.empty())
{
ret = working + '-' + ret;
for(unsigned idx=0; idx<length; idx++)
{
ret += getBitN(input, 7 - idx) ? '1' : '0';
}
}
return ret;
}