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); }
/// <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; }
/// <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); }
public override Int64sRef Next(int count) { Debug.Assert(nextValues.Length >= 0); Debug.Assert(count > 0); Debug.Assert(nextValues.Offset + nextValues.Length <= nextValues.Int64s.Length); nextValues.Offset += nextValues.Length; int remaining = m_valueCount - position - 1; if (remaining <= 0) { throw new System.IO.EndOfStreamException(); } count = Math.Min(remaining, count); if (nextValues.Offset == nextValues.Int64s.Length) { long remainingBlocks = format.ByteCount(packedIntsVersion, remaining, m_bitsPerValue); int blocksToRead = (int)Math.Min(remainingBlocks, nextBlocks.Length); m_in.ReadBytes(nextBlocks, 0, blocksToRead); if (blocksToRead < nextBlocks.Length) { Arrays.Fill(nextBlocks, blocksToRead, nextBlocks.Length, (byte)0); } bulkOperation.Decode(nextBlocks, 0, nextValues.Int64s, 0, iterations); nextValues.Offset = 0; } nextValues.Length = Math.Min(nextValues.Int64s.Length - nextValues.Offset, count); position += nextValues.Length; return(nextValues); }
private void Flush() { encoder.Encode(nextValues, 0, nextBlocks, 0, iterations); int blockCount = (int)format.ByteCount(PackedInt32s.VERSION_CURRENT, off, m_bitsPerValue); m_out.WriteBytes(nextBlocks, blockCount); Arrays.Fill(nextValues, 0L); off = 0; }