Class HuffmanTree<VALUE>

  • Type Parameters:
    VALUE - the value that wants to be encoded.

    public final class HuffmanTree<VALUE>
    extends java.lang.Object
    Huffman tree coder that takes input from a Multiset and returns huffman codes getHuffmanCodes(). 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
      void addAll​(com.google.common.collect.Multiset<VALUE> multiSet)
      Bulk inserts the given multiset into this huffman tree.
      VALUE decode​(de.jungblut.math.sparse.SparseBitVector vector)
      Decodes a given vector.
      int getCardinality()  
      java.util.Map<VALUE,​de.jungblut.math.sparse.SparseBitVector> getHuffmanCodes()
      Bulk returns all generated Huffman codes as a bit vector representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HuffmanTree

        public HuffmanTree()
    • 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.