Added Huffman Coding.

This commit is contained in:
Jacob Signorovitch
2024-12-16 09:17:19 -05:00
parent 213239b469
commit c745b21b85
4 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
package huffman_coding;
import java.util.ArrayList;
import tester.Tester;
class Examples {
void testTest(Tester t) {
t.checkExpect(1, 1);
}
}
class Huffman {
ArrayList<String> charset; // Character set.
ArrayList<Boolean> freqs; // Relative frequencies of characters.
Huffman(ArrayList<String> charset, ArrayList<Boolean> freqs) {
if (charset.size() != freqs.size()) throw new IllegalArgumentException(
"Character set must match frequencies."
);
if (charset.size() < 2) throw new IllegalArgumentException(
"Character set too small."
);
this.charset = charset;
this.freqs = freqs;
}
}
// Binary tree.
interface ITree<T> {}
class Node<T> implements ITree<T> {
ITree<T> l;
ITree<T> r;
Node(ITree<T> l, ITree<T> r) {
this.l = l;
this.r = r;
}
}
class Leaf<T> implements ITree<T> {}