Package de.jungblut.datastructure
Class HuffmanTree<VALUE>
- java.lang.Object
-
- de.jungblut.datastructure.HuffmanTree<VALUE>
-
- Type Parameters:
VALUE- the value that wants to be encoded.
public final class HuffmanTree<VALUE> extends java.lang.ObjectHuffman tree coder that takes input from aMultisetand returns huffman codesgetHuffmanCodes(). Features generic and object tree representation which uses lots of ram and will be replaced with an array based version soon.- Author:
- thomas.jungblut
-
-
Constructor Summary
Constructors Constructor Description HuffmanTree()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAll(com.google.common.collect.Multiset<VALUE> multiSet)Bulk inserts the given multiset into this huffman tree.VALUEdecode(de.jungblut.math.sparse.SparseBitVector vector)Decodes a given vector.intgetCardinality()java.util.Map<VALUE,de.jungblut.math.sparse.SparseBitVector>getHuffmanCodes()Bulk returns all generated Huffman codes as a bit vector representation.
-
-
-
Method Detail
-
addAll
public void addAll(com.google.common.collect.Multiset<VALUE> multiSet)
Bulk inserts the given multiset into this huffman tree.- Parameters:
multiSet- a multiset that contains value mappings to their frequency.
-
getHuffmanCodes
public java.util.Map<VALUE,de.jungblut.math.sparse.SparseBitVector> getHuffmanCodes()
Bulk returns all generated Huffman codes as a bit vector representation.- Returns:
- the mapping between value and its binary code.
-
decode
public VALUE decode(de.jungblut.math.sparse.SparseBitVector vector)
Decodes a given vector.- Parameters:
vector- the bit vector to decode.- Returns:
- null if the code doesn't exist, or the value if it does.
-
getCardinality
public int getCardinality()
- Returns:
- the number of bits needed to encode every item in this tree uniquely.
-
-