Ejemplo n.º 1
0
 internal Packed8ThreeBlocks(int packedIntsVersion, DataInput @in, int valueCount)
     : this(valueCount)
 {
     @in.ReadBytes(Blocks, 0, 3 * valueCount);
     // because packed ints have not always been byte-aligned
     var remaining = (int)(PackedInts.Format.PACKED.ByteCount(packedIntsVersion, valueCount, 24) - 3L * valueCount * 1);
     for (int i = 0; i < remaining; ++i)
     {
         @in.ReadByte();
     }
 }
Ejemplo n.º 2
0
 internal Direct32(int packedIntsVersion, DataInput @in, int valueCount)
     : this(valueCount)
 {
     for (int i = 0; i < valueCount; ++i)
     {
         Values[i] = @in.ReadInt();
     }
     // because packed ints have not always been byte-aligned
     int remaining = (int)(PackedInts.Format.PACKED.ByteCount(packedIntsVersion, valueCount, 32) - 4L * valueCount);
     for (int i = 0; i < remaining; ++i)
     {
         @in.ReadByte();
     }
 }
Ejemplo n.º 3
0
 internal Packed16ThreeBlocks(int packedIntsVersion, DataInput @in, int valueCount)
     : this(valueCount)
 {
     for (int i = 0; i < 3 * valueCount; ++i)
     {
         Blocks[i] = @in.ReadShort();
     }
     // because packed ints have not always been byte-aligned
     int remaining = (int)(PackedInts.Format.PACKED.ByteCount(packedIntsVersion, valueCount, 48) - 3L * valueCount * 2);
     for (int i = 0; i < remaining; ++i)
     {
         @in.ReadByte();
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Decompress at least <code>decompressedLen</code> bytes into
        /// <code>dest[dOff:]</code>. Please note that <code>dest</code> must be large
        /// enough to be able to hold <b>all</b> decompressed data (meaning that you
        /// need to know the total decompressed length).
        /// </summary>
        public static int Decompress(DataInput compressed, int decompressedLen, byte[] dest, int dOff)
        {
            int destEnd = dest.Length;

            do
            {
                // literals
                int token = compressed.ReadByte() & 0xFF;
                int literalLen = (int)(((uint)token) >> 4);

                if (literalLen != 0)
                {
                    if (literalLen == 0x0F)
                    {
                        byte len;
                        while ((len = compressed.ReadByte()) == 0xFF)
                        {
                            literalLen += 0xFF;
                        }
                        literalLen += len & 0xFF;
                    }
                    compressed.ReadBytes(dest, dOff, literalLen);
                    dOff += literalLen;
                }

                if (dOff >= decompressedLen)
                {
                    break;
                }

                // matchs
                var byte1 = compressed.ReadByte();
                var byte2 = compressed.ReadByte();
                int matchDec = (byte1 & 0xFF) | ((byte2 & 0xFF) << 8);
                Debug.Assert(matchDec > 0);

                int matchLen = token & 0x0F;
                if (matchLen == 0x0F)
                {
                    int len;
                    while ((len = compressed.ReadByte()) == 0xFF)
                    {
                        matchLen += 0xFF;
                    }
                    matchLen += len & 0xFF;
                }
                matchLen += MIN_MATCH;

                // copying a multiple of 8 bytes can make decompression from 5% to 10% faster
                int fastLen = (int)((matchLen + 7) & 0xFFFFFFF8);
                if (matchDec < matchLen || dOff + fastLen > destEnd)
                {
                    // overlap -> naive incremental copy
                    for (int @ref = dOff - matchDec, end = dOff + matchLen; dOff < end; ++@ref, ++dOff)
                    {
                        dest[dOff] = dest[@ref];
                    }
                }
                else
                {
                    // no overlap -> arraycopy
                    Array.Copy(dest, dOff - matchDec, dest, dOff, fastLen);
                    dOff += matchLen;
                }
            } while (dOff < decompressedLen);

            return dOff;
        }