/usr/include/claw/impl/lzw_encoder.tpp is in libclaw-dev 1.7.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | /**
* \file lzw_encoder.tpp
* \brief Implementation of the claw::lzw_encoder class.
* \author Julien Jorge
*/
#include <map>
/*----------------------------------------------------------------------------*/
/**
* \brief Encode a sequence of datas.
* \param input Where we read the uncompressed data.
* \param output Where we write compressed data.
*/
template<typename InputBuffer, typename OutputBuffer>
void claw::lzw_encoder<InputBuffer, OutputBuffer>::encode
( input_buffer_type& input, output_buffer_type& output ) const
{
typedef std::pair<unsigned int, unsigned int> word;
if ( !input.end_of_data() )
{
std::map<word, unsigned int> table;
unsigned int symbol = input.get_next();
unsigned int prefix_code = symbol;
unsigned int next_code = input.symbols_count();
while ( !input.end_of_data() && (next_code != output.max_code()) )
{
symbol = input.get_next();
word new_word(prefix_code, symbol);
if ( table.find(new_word) != table.end() )
prefix_code = table[new_word];
else
{
output.write(prefix_code);
output.new_code(next_code);
table[new_word] = next_code;
prefix_code = symbol;
++next_code;
}
}
output.write(prefix_code);
}
} // lzw_encoder::encode()
|