Added Huffman Coding.
This commit is contained in:
46
huffman_coding/src/huffman_coding/Main.java
Normal file
46
huffman_coding/src/huffman_coding/Main.java
Normal 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> {}
|
Reference in New Issue
Block a user