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

28
huffman_coding/.project Normal file
View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>huffman_coding</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1734357118166</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

View File

@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View File

@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21

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> {}