/// <summary>
        /// Builds Tree.
        /// </summary>
        /// <param name="input">
        /// input byte array to build tree.
        /// </param>
        /// <param name="treeNodes"></param>
        /// <returns></returns>
        public PrefixCodeNode PrefixCodeTreeRebuild(byte[] input, ref PrefixCodeNode[] treeNodes)
        {
            PrefixCodeNode root = new PrefixCodeNode();

            PrefixCodeSymbol[] symbolInfo = new PrefixCodeSymbol[512];

            UInt32 i;
            UInt32 j;
            UInt32 mask;
            UInt32 bits;

            for (i = 0; i < 1024; i++)
            {
                treeNodes[i].symbol   = 0;
                treeNodes[i].leaf     = false;
                treeNodes[i].Child[0] = null;
                treeNodes[i].Child[1] = null;
            }

            for (i = 0; i < 256; i++)
            {
                symbolInfo[2 * i].symbol = (UInt16)(2 * i);
                symbolInfo[2 * i].length = (UInt16)(input[i] & 15);

                symbolInfo[2 * i + 1].symbol = (UInt16)(2 * i + 1);
                symbolInfo[2 * i + 1].length = (UInt16)(input[i] >> 4);
            }

            SortSymbols(ref symbolInfo);

            i = 0;
            while ((i < 512) && (symbolInfo[i].length == 0))
            {
                i++;
            }

            mask = 0;
            bits = 1;

            root      = treeNodes[0];
            root.leaf = false;

            j = 1;

            for (; i < 512; i++)
            {
                treeNodes[j].symbol = symbolInfo[i].symbol;
                treeNodes[j].leaf   = true;
                mask = mask << (int)(symbolInfo[i].length - bits);
                bits = symbolInfo[i].length;
                j    = PrefixCodeTreeAddLeaf(ref treeNodes, j, mask, bits);
                mask++;
            }

            return(root);
        }
 /// <summary>
 /// Compares two symbols
 /// </summary>
 /// <param name="a">
 /// First Symbol
 /// </param>
 /// <param name="b">
 /// Second Symbol
 /// </param>
 /// <returns></returns>
 public int CompareSymbols(PrefixCodeSymbol a, PrefixCodeSymbol b)
 {
     if (a.length < b.length)
     {
         return(-1);
     }
     else if (a.length > b.length)
     {
         return(1);
     }
     else if (a.symbol < b.symbol)
     {
         return(-1);
     }
     else if (a.symbol > b.symbol)
     {
         return(1);
     }
     else
     {
         return(0);
     }
 }