Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public final void createCodeTable(Reader src) throws IOException {
  2. encodeTable = new HashMap<>();
  3. int c = src.read();
  4. while (c != -1) {
  5. countChar(c);
  6. }
  7. // Phase 1 - count character frequencies
  8. // phase 2 - build the huffman tree
  9. // assign codes to each character
  10. //print encode table, to enable checking of output
  11. for (int ch : encodeTable.keySet())
  12. System.out.println(encodeTable.get(c));
  13. }
  14.  
  15. public void countChar(int c) {
  16. HuffmanNode value = encodeTable.get(c);
  17. if (value == null) {
  18. HuffmanNode node = new HuffmanNode(c);
  19. node.count++;
  20. encodeTable.put(c, node);
  21. }else {
  22. value.count++;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement