BitReverse() public static method

public static BitReverse ( uint code, int length ) : uint
code uint
length int
return uint
コード例 #1
0
ファイル: HuffmanTree.cs プロジェクト: dimcc/hprose-dotnet
        private uint[] CalculateHuffmanCode()
        {
            uint[] numArray        = new uint[0x11];
            byte[] codeLengthArray = this.codeLengthArray;
            for (int i = 0; i < codeLengthArray.Length; i++)
            {
                int index = codeLengthArray[i];
                numArray[index]++;
            }
            numArray[0] = 0;
            uint[] numArray2 = new uint[0x11];
            uint   num2      = 0;

            for (int j = 1; j <= 0x10; j++)
            {
                numArray2[j] = (num2 + numArray[j - 1]) << 1;
            }
            uint[] numArray3 = new uint[0x120];
            for (int k = 0; k < this.codeLengthArray.Length; k++)
            {
                int length = this.codeLengthArray[k];
                if (length > 0)
                {
                    numArray3[k] = DecodeHelper.BitReverse(numArray2[length], length);
                    numArray2[length]++;
                }
            }
            return(numArray3);
        }
コード例 #2
0
        // Calculate the huffman code for each character based on the code length for each character.
        // This algorithm is described in standard RFC 1951
        uint[] CalculateHuffmanCode()
        {
            uint[] bitLengthCount = new uint[17];
            foreach (int codeLength in codeLengthArray)
            {
                bitLengthCount[codeLength]++;
            }
            bitLengthCount[0] = 0;  // clear count for length 0

            uint[] nextCode = new uint[17];
            uint   tempCode = 0;

            for (int bits = 1; bits <= 16; bits++)
            {
                tempCode       = (tempCode + bitLengthCount[bits - 1]) << 1;
                nextCode[bits] = tempCode;
            }

            uint[] code = new uint[MaxLiteralTreeElements];
            for (int i = 0; i < codeLengthArray.Length; i++)
            {
                int len = codeLengthArray[i];

                if (len > 0)
                {
                    code[i] = DecodeHelper.BitReverse(nextCode[len], len);
                    nextCode[len]++;
                }
            }
            return(code);
        }