14 template<
typename InputBuffer,
typename OutputBuffer>
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);