コード例 #1
0
        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();
        }
コード例 #2
0
 internal VarLenCharEncoding(IEncodingNode root)
 {
     this.root  = root;
     this.codes = new Dictionary <char, byte[]>();
     Traverse(root, codes, new List <byte>());
     this.decodingTable = BuildDecodingTable();
 }
コード例 #3
0
            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);
            }
コード例 #4
0
 public void Pop()
 {
     current = states.Pop();
 }
コード例 #5
0
 public BitDecoder(IEncodingNode root)
 {
     this.root    = root;
     this.current = root;
 }
コード例 #6
0
 public HuffmanEncoding(IEncodingNode root)
     : base(root)
 {
 }
コード例 #7
0
 public BalancedByWeightEncoding(IEncodingNode root)
     : base(root)
 {
 }