示例#1
0
        public void Dump()
        {
            bool[] seen = new bool[Entries];
            HuffLeafNode[] entryNodes = new HuffLeafNode[Entries];

            RootNode.Visit(delegate(HuffLeafNode node)
            {
                seen[node.Code] = true;
                entryNodes[node.Code] = node;
            });

            for (int i = 0; i < Entries; ++i)
            {
                if (seen[i])
                {
                    Console.Write("    {0}: {1}", i, entryNodes[i].Codeword());

                    if (LookupType == 1)
                    {
                        Console.Write(": ");

                        float[] vq = Lookup[i];

                        for (int dim = 0; dim < Dimensions; ++dim)
                        {
                            if (dim != 0)
                                Console.Write(", ");
                            Console.Write(vq[dim]);
                        }
                    }

                    Console.WriteLine();
                }
            }
        }
示例#2
0
        public override HuffLeafNode Insert(int code, int desiredDepth)
        {
            if (desiredDepth > 1)
            {
                if (Zero == null)
                    Zero = new HuffInternalNode() { Parent = this };

                HuffLeafNode h = Zero.Insert(code, desiredDepth-1);
                if (h != null)
                    return h;

                if (One == null)
                    One = new HuffInternalNode() { Parent = this };

                h = One.Insert(code, desiredDepth-1);
                if (h != null)
                    return h;

                return null;
            }
            else if (desiredDepth == 1)
            {
                if (Zero != null && One != null)
                    return null;

                HuffLeafNode leaf = new HuffLeafNode() { Parent=this, Code = code };

                if (Zero == null)
                    Zero = leaf;
                else
                    One = leaf;

                return leaf;
            }
            else
                throw new ArgumentOutOfRangeException("desiredDepth");
        }