Beispiel #1
0
        private unsafe void LoadDistTree()
        {
            int n, m, p, code;

            AcedUtils.Fill(0, _pBitLen, AcedConsts.DistCount);
            LoadCharDistLengths(GetNBits(6) + 1);
            AcedUtils.Fill(0, _pDistTree, AcedConsts.DistTreeSize);
            _pNextCode[1]  = 0;
            _pNextCode[2]  = n = _pBitCount[1] << 1;
            _pNextCode[3]  = n = (n + _pBitCount[2]) << 1;
            _pNextCode[4]  = n = (n + _pBitCount[3]) << 1;
            _pNextCode[5]  = n = (n + _pBitCount[4]) << 1;
            _pNextCode[6]  = n = (n + _pBitCount[5]) << 1;
            _pNextCode[7]  = n = (n + _pBitCount[6]) << 1;
            _pNextCode[8]  = n = (n + _pBitCount[7]) << 1;
            _pNextCode[9]  = n = (n + _pBitCount[8]) << 1;
            _pNextCode[10] = n = (n + _pBitCount[9]) << 1;
            _pNextCode[11] = n = (n + _pBitCount[10]) << 1;
            _pNextCode[12] = n = (n + _pBitCount[11]) << 1;
            _pNextCode[13] = n = (n + _pBitCount[12]) << 1;
            _pNextCode[14] = n = (n + _pBitCount[13]) << 1;
            var treeLen = 2;

            for (var i = 0; i < AcedConsts.DistCount; i++)
            {
                n = _pBitLen[i];
                if (n == 0)
                {
                    continue;
                }
                m             = _pNextCode[n];
                code          = (int)AcedUtils.ReverseBits((uint)m, n);
                _pNextCode[n] = m + 1;
                p             = 1;
                while (true)
                {
                    p     += code & 1;
                    code >>= 1;
                    n--;
                    if (n != 0)
                    {
                        m = p;
                        p = _pDistTree[p];
                        if (p != 0)
                        {
                            continue;
                        }
                        p             = treeLen + 1;
                        treeLen       = p + 1;
                        _pDistTree[m] = p;
                    }
                    else
                    {
                        _pDistTree[p] = -i;
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        private unsafe void LoadChLenTree()
        {
            int n, m, p, i, code;

            AcedUtils.Fill(0, _pBitCount, AcedConsts.MaxChLenBits + 1);
            for (i = 0; i < AcedConsts.ChLenCount; i++)
            {
                n           = GetNBits(3);
                _pBitLen[i] = n;
                _pBitCount[n]++;
            }

            AcedUtils.Fill(0, _pChLenTree, AcedConsts.ChLenTreeSize);
            _pNextCode[1] = 0;
            _pNextCode[2] = n = _pBitCount[1] << 1;
            _pNextCode[3] = n = (n + _pBitCount[2]) << 1;
            _pNextCode[4] = n = (n + _pBitCount[3]) << 1;
            _pNextCode[5] = n = (n + _pBitCount[4]) << 1;
            _pNextCode[6] = n = (n + _pBitCount[5]) << 1;
            _pNextCode[7] = n = (n + _pBitCount[6]) << 1;
            var treeLen = 2;

            for (i = 0; i < AcedConsts.ChLenCount; i++)
            {
                n = _pBitLen[i];
                if (n == 0)
                {
                    continue;
                }
                m             = _pNextCode[n];
                code          = (int)AcedUtils.ReverseBits((uint)m, n);
                _pNextCode[n] = m + 1;
                p             = 1;
                while (true)
                {
                    p     += code & 1;
                    code >>= 1;
                    n--;
                    if (n != 0)
                    {
                        m = p;
                        p = _pChLenTree[p];
                        if (p != 0)
                        {
                            continue;
                        }
                        p              = treeLen + 1;
                        treeLen        = p + 1;
                        _pChLenTree[m] = p;
                    }
                    else
                    {
                        _pChLenTree[p] = -i;
                        break;
                    }
                }
            }
        }