public IDecoder <T> GetDecoder(IHuffmanTreeNode <T> root)
 {
     if (root.IsLeaf)
     {
         return(new OneSymbolDecoder <T>(root.Value));
     }
     return(new HuffmanDecoder <T>(root));
 }
Exemple #2
0
 private void Decode(IDecoderInput input, IDecoderOutput <T> output, IHuffmanTreeNode <T> currentNode)
 {
     while (!output.IsEnd())
     {
         var bit = input.Read();
         currentNode = bit ? currentNode.RightChild : currentNode.LeftChild;
         if (currentNode.IsLeaf)
         {
             output.Write(currentNode.Value);
             currentNode = root;
         }
     }
 }
Exemple #3
0
 private void GenerateSymbolEncodingDic(IHuffmanTreeNode <T> node, List <bool> currentEncoding)
 {
     if (node.IsLeaf)
     {
         EncodingDictionary.Add(node.Value, currentEncoding.ToArray());
         return;
     }
     currentEncoding.Add(false);
     GenerateSymbolEncodingDic(node.LeftChild, currentEncoding);
     currentEncoding.RemoveAt(currentEncoding.Count - 1);
     currentEncoding.Add(true);
     GenerateSymbolEncodingDic(node.RightChild, currentEncoding);
     currentEncoding.RemoveAt(currentEncoding.Count - 1);
 }
Exemple #4
0
 public HuffmanCoder(IHuffmanTreeNode <T> root)
 {
     GenerateSymbolEncodingDic(root, new List <bool>());
 }
Exemple #5
0
 public HuffmanDecoder(IHuffmanTreeNode <T> root)
 {
     this.root = root;
 }