Esempio n. 1
0
        /// <summary>
        /// Compute the number of bytes required to encode a block of values that require
        /// <paramref name="bitsPerValue"/> bits per value with format <paramref name="format"/>.
        /// </summary>
        private static int EncodedSize(PackedInt32s.Format format, int packedIntsVersion, int bitsPerValue)
        {
            long byteCount = format.ByteCount(packedIntsVersion, Lucene41PostingsFormat.BLOCK_SIZE, bitsPerValue);

            Debug.Assert(byteCount >= 0 && byteCount <= int.MaxValue, byteCount.ToString());
            return((int)byteCount);
        }
Esempio n. 2
0
        /// <summary>
        /// Restore a <see cref="ForUtil"/> from a <see cref="DataInput"/>.
        /// </summary>
        internal ForUtil(DataInput @in)
        {
            int packedIntsVersion = @in.ReadVInt32();

            PackedInt32s.CheckVersion(packedIntsVersion);
            encodedSizes = new int[33];
            encoders     = new PackedInt32s.IEncoder[33];
            decoders     = new PackedInt32s.IDecoder[33];
            iterations   = new int[33];

            for (int bpv = 1; bpv <= 32; ++bpv)
            {
                var code         = @in.ReadVInt32();
                var formatId     = (int)((uint)code >> 5);
                var bitsPerValue = (code & 31) + 1;

                PackedInt32s.Format format = PackedInt32s.Format.ById(formatId);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(format.IsSupported(bitsPerValue));
                }
                encodedSizes[bpv] = EncodedSize(format, packedIntsVersion, bitsPerValue);
                encoders[bpv]     = PackedInt32s.GetEncoder(format, packedIntsVersion, bitsPerValue);
                decoders[bpv]     = PackedInt32s.GetDecoder(format, packedIntsVersion, bitsPerValue);
                iterations[bpv]   = ComputeIterations(decoders[bpv]);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an array with content retrieved from the given <see cref="DataInput"/>. </summary>
        /// <param name="in">       A <see cref="DataInput"/>, positioned at the start of Packed64-content. </param>
        /// <param name="valueCount">  The number of elements. </param>
        /// <param name="bitsPerValue"> The number of bits available for any given value. </param>
        /// <exception cref="IOException"> If the values for the backing array could not
        ///                             be retrieved. </exception>
        public Packed64(int packedIntsVersion, DataInput @in, int valueCount, int bitsPerValue)
            : base(valueCount, bitsPerValue)
        {
            PackedInt32s.Format format = PackedInt32s.Format.PACKED;
            long byteCount             = format.ByteCount(packedIntsVersion, valueCount, bitsPerValue);             // to know how much to read
            int  longCount             = format.Int64Count(PackedInt32s.VERSION_CURRENT, valueCount, bitsPerValue); // to size the array

            blocks = new long[longCount];
            // read as many longs as we can
            for (int i = 0; i < byteCount / 8; ++i)
            {
                blocks[i] = @in.ReadInt64();
            }
            int remaining = (int)(byteCount % 8);

            if (remaining != 0)
            {
                // read the last bytes
                long lastLong = 0;
                for (int i = 0; i < remaining; ++i)
                {
                    lastLong |= (@in.ReadByte() & 0xFFL) << (56 - i * 8);
                }
                blocks[blocks.Length - 1] = lastLong;
            }
            maskRight         = (~0L << (BLOCK_SIZE - bitsPerValue)).TripleShift(BLOCK_SIZE - bitsPerValue);
            bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
        }
Esempio n. 4
0
        /// <summary>
        /// Creates an array with the internal structures adjusted for the given
        /// limits and initialized to 0. </summary>
        /// <param name="valueCount">   The number of elements. </param>
        /// <param name="bitsPerValue"> The number of bits available for any given value. </param>
        public Packed64(int valueCount, int bitsPerValue)
            : base(valueCount, bitsPerValue)
        {
            PackedInt32s.Format format = PackedInt32s.Format.PACKED;
            int longCount = format.Int64Count(PackedInt32s.VERSION_CURRENT, valueCount, bitsPerValue);

            this.blocks       = new long[longCount];
            maskRight         = (~0L << (BLOCK_SIZE - bitsPerValue)).TripleShift(BLOCK_SIZE - bitsPerValue);
            bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
        }
Esempio n. 5
0
 internal PackedWriter(PackedInt32s.Format format, DataOutput @out, int valueCount, int bitsPerValue, int mem)
     : base(@out, valueCount, bitsPerValue)
 {
     this.format = format;
     encoder     = BulkOperation.Of(format, bitsPerValue);
     iterations  = encoder.ComputeIterations(valueCount, mem);
     nextBlocks  = new byte[iterations * encoder.ByteBlockCount];
     nextValues  = new long[iterations * encoder.ByteValueCount];
     off         = 0;
     written     = 0;
     finished    = false;
 }
Esempio n. 6
0
 internal PackedReaderIterator(PackedInt32s.Format format, int packedIntsVersion, int valueCount, int bitsPerValue, DataInput @in, int mem)
     : base(valueCount, bitsPerValue, @in)
 {
     this.format            = format;
     this.packedIntsVersion = packedIntsVersion;
     bulkOperation          = BulkOperation.Of(format, bitsPerValue);
     iterations             = Iterations(mem);
     Debug.Assert(valueCount == 0 || iterations > 0);
     nextBlocks        = new byte[iterations * bulkOperation.ByteBlockCount];
     nextValues        = new Int64sRef(new long[iterations * bulkOperation.ByteValueCount], 0, 0);
     nextValues.Offset = nextValues.Int64s.Length;
     position          = -1;
 }
Esempio n. 7
0
            internal virtual int PforBlockSize(int bitsPerValue, int numExceptions, int bitsPerException)
            {
                PackedInt32s.Format format = PackedInt32s.Format.PACKED;
                long blockSize             = 1 + format.ByteCount(PackedInt32s.VERSION_CURRENT, BLOCK_SIZE, bitsPerValue); // header: number of bits per value

                if (numExceptions > 0)
                {
                    blockSize += 2 + numExceptions + format.ByteCount(PackedInt32s.VERSION_CURRENT, numExceptions, bitsPerException); // indices of the exceptions -  2 additional bytes in case of exceptions: numExceptions and bitsPerException
                }
                if (bufferSize < BLOCK_SIZE)
                {
                    blockSize += 1; // length of the block
                }
                return((int)blockSize);
            }
Esempio n. 8
0
 public static BulkOperation Of(PackedInt32s.Format format, int bitsPerValue)
 {
     if (format == PackedInt32s.Format.PACKED)
     {
         Debug.Assert(packedBulkOps[bitsPerValue - 1] != null);
         return(packedBulkOps[bitsPerValue - 1]);
     }
     else if (format == PackedInt32s.Format.PACKED_SINGLE_BLOCK)
     {
         Debug.Assert(packedSingleBlockBulkOps[bitsPerValue - 1] != null);
         return(packedSingleBlockBulkOps[bitsPerValue - 1]);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Creates an array with the internal structures adjusted for the given
        /// limits and initialized to 0. </summary>
        /// <param name="valueCount">   The number of elements. </param>
        /// <param name="bitsPerValue"> The number of bits available for any given value. </param>
        public Packed64(int valueCount, int bitsPerValue)
            : base(valueCount, bitsPerValue)
        {
            PackedInt32s.Format format = PackedInt32s.Format.PACKED;
            int longCount = format.Int64Count(PackedInt32s.VERSION_CURRENT, valueCount, bitsPerValue);

            this.blocks = new long[longCount];
            //            MaskRight = ~0L << (int)((uint)(BLOCK_SIZE - bitsPerValue) >> (BLOCK_SIZE - bitsPerValue));    //original
            //            MaskRight = (uint)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue);          //mod

            /*var a = ~0L << (int)((uint)(BLOCK_SIZE - bitsPerValue) >> (BLOCK_SIZE - bitsPerValue));    //original
             * var b = (uint)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue);          //mod
             * if (Debugging.AssertsEnabled) Debugging.Assert(a == b, "a: " + a, ", b: " + b);*/

            maskRight = (long)((ulong)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue));    //mod

            //if (Debugging.AssertsEnabled) Debugging.Assert((long)((ulong)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue)) == (uint)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue));

            bpvMinusBlockSize = bitsPerValue - BLOCK_SIZE;
        }
Esempio n. 10
0
 public static BulkOperation Of(PackedInt32s.Format format, int bitsPerValue)
 {
     if (format == PackedInt32s.Format.PACKED)
     {
         if (Debugging.AssertsEnabled)
         {
             Debugging.Assert(packedBulkOps[bitsPerValue - 1] != null);
         }
         return(packedBulkOps[bitsPerValue - 1]);
     }
     else if (format == PackedInt32s.Format.PACKED_SINGLE_BLOCK)
     {
         if (Debugging.AssertsEnabled)
         {
             Debugging.Assert(packedSingleBlockBulkOps[bitsPerValue - 1] != null);
         }
         return(packedSingleBlockBulkOps[bitsPerValue - 1]);
     }
     else
     {
         throw AssertionError.Create();
     }
 }
Esempio n. 11
0
 internal PagedMutable(long size, int pageSize, int bitsPerValue, PackedInt32s.Format format)
     : base(bitsPerValue, size, pageSize)
 {
     this.format = format;
 }