Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final void createCodeTable(Reader src) throws IOException {
- encodeTable = new HashMap<>();
- int c = src.read();
- while (c != -1) {
- countChar(c);
- }
- // Phase 1 - count character frequencies
- // phase 2 - build the huffman tree
- // assign codes to each character
- //print encode table, to enable checking of output
- for (int ch : encodeTable.keySet())
- System.out.println(encodeTable.get(c));
- }
- public void countChar(int c) {
- HuffmanNode value = encodeTable.get(c);
- if (value == null) {
- HuffmanNode node = new HuffmanNode(c);
- node.count++;
- encodeTable.put(c, node);
- }else {
- value.count++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement