2 * \file lzw_encoder.tpp
3 * \brief Implementation of the claw::lzw_encoder class.
8/*----------------------------------------------------------------------------*/
10 * \brief Encode a sequence of datas.
11 * \param input Where we read the uncompressed data.
12 * \param output Where we write compressed data.
14template<typename InputBuffer, typename OutputBuffer>
15void claw::lzw_encoder<InputBuffer, OutputBuffer>::encode
16( input_buffer_type& input, output_buffer_type& output ) const
18 typedef std::pair<unsigned int, unsigned int> word;
20 if ( !input.end_of_data() )
22 std::map<word, unsigned int> table;
24 unsigned int symbol = input.get_next();
25 unsigned int prefix_code = symbol;
26 unsigned int next_code = input.symbols_count();
28 while ( !input.end_of_data() && (next_code != output.max_code()) )
30 symbol = input.get_next();
32 word new_word(prefix_code, symbol);
34 if ( table.find(new_word) != table.end() )
35 prefix_code = table[new_word];
38 output.write(prefix_code);
39 output.new_code(next_code);
40 table[new_word] = next_code;
47 output.write(prefix_code);
49} // lzw_encoder::encode()