private void Traverse(IEncodingNode root, Dictionary <char, byte[]> codes, List <byte> current) { var leaf = root as IEncodingLeafNode; if (leaf != null) { codes[leaf.V] = current.ToArray(); return; } var node = root as IEncodingTreeNode; if (node != null) { current.Add(LeftValue); Traverse(node.Left, codes, current); current.RemoveAt(current.Count - 1); current.Add(RightValue); Traverse(node.Right, codes, current); current.RemoveAt(current.Count - 1); return; } throw new InvalidOperationException(); }
internal VarLenCharEncoding(IEncodingNode root) { this.root = root; this.codes = new Dictionary <char, byte[]>(); Traverse(root, codes, new List <byte>()); this.decodingTable = BuildDecodingTable(); }
public char Next(bool p) { states.Push(current); var node = current as IEncodingTreeNode; if (node != null) { if (p == (LeftValue == 1)) { current = node.Left; } else { current = node.Right; } } var leaf = current as IEncodingLeafNode; if (leaf != null) { current = root; if (leaf.V == TerminalChar) { return(TerminalChar); } else { return(leaf.V); } } return(TerminalChar); }
public void Pop() { current = states.Pop(); }
public BitDecoder(IEncodingNode root) { this.root = root; this.current = root; }
public HuffmanEncoding(IEncodingNode root) : base(root) { }
public BalancedByWeightEncoding(IEncodingNode root) : base(root) { }