public IDecoder <T> GetDecoder(IHuffmanTreeNode <T> root) { if (root.IsLeaf) { return(new OneSymbolDecoder <T>(root.Value)); } return(new HuffmanDecoder <T>(root)); }
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; } } }
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); }
public HuffmanCoder(IHuffmanTreeNode <T> root) { GenerateSymbolEncodingDic(root, new List <bool>()); }
public HuffmanDecoder(IHuffmanTreeNode <T> root) { this.root = root; }