/// <summary> /// Creates an array with content retrieved from the given DataInput. </summary> /// <param name="in"> a 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="java.io.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) { PackedInts.Format format = PackedInts.Format.PACKED; long byteCount = format.ByteCount(packedIntsVersion, valueCount, bitsPerValue); // to know how much to read int longCount = format.LongCount(PackedInts.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.ReadLong(); } 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 = (long)((ulong)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue)); BpvMinusBlockSize = bitsPerValue - BLOCK_SIZE; }
/// <summary> /// Compute the number of bytes required to encode a block of values that require /// <code>bitsPerValue</code> bits per value with format <code>format</code>. /// </summary> private static int EncodedSize(PackedInts.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); }
internal PackedWriter(PackedInts.Format format, DataOutput @out, int valueCount, int bitsPerValue, int mem) : base(@out, valueCount, bitsPerValue) { this.Format_Renamed = 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; }
internal PackedReaderIterator(PackedInts.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_Renamed = Iterations(mem); Debug.Assert(valueCount == 0 || Iterations_Renamed > 0); NextBlocks = new byte[Iterations_Renamed * BulkOperation.ByteBlockCount()]; NextValues = new LongsRef(new long[Iterations_Renamed * BulkOperation.ByteValueCount()], 0, 0); NextValues.Offset = NextValues.Longs.Length; Position = -1; }
internal virtual int PforBlockSize(int bitsPerValue, int numExceptions, int bitsPerException) { PackedInts.Format format = PackedInts.Format.PACKED; long blockSize = 1 + format.ByteCount(PackedInts.VERSION_CURRENT, BLOCK_SIZE, bitsPerValue); // header: number of bits per value if (numExceptions > 0) { blockSize += 2 + numExceptions + format.ByteCount(PackedInts.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); }
public static BulkOperation Of(PackedInts.Format format, int bitsPerValue) { if (format == PackedInts.Format.PACKED) { Debug.Assert(PackedBulkOps[bitsPerValue - 1] != null); return(PackedBulkOps[bitsPerValue - 1]); } else if (format == PackedInts.Format.PACKED_SINGLE_BLOCK) { Debug.Assert(PackedSingleBlockBulkOps[bitsPerValue - 1] != null); return(PackedSingleBlockBulkOps[bitsPerValue - 1]); } else { throw new InvalidOperationException(); } }
/// <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) { PackedInts.Format format = PackedInts.Format.PACKED; int longCount = format.LongCount(PackedInts.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 * Debug.Assert(a == b, "a: " + a, ", b: " + b);*/ MaskRight = (long)((ulong)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue)); //mod //Debug.Assert((long)((ulong)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue)) == (uint)(~0L << (BLOCK_SIZE - bitsPerValue)) >> (BLOCK_SIZE - bitsPerValue)); BpvMinusBlockSize = bitsPerValue - BLOCK_SIZE; }
/// <summary> /// Restore a <seealso cref="ForUtil"/> from a <seealso cref="DataInput"/>. /// </summary> public ForUtil(DataInput @in) { int packedIntsVersion = @in.ReadVInt(); PackedInts.CheckVersion(packedIntsVersion); EncodedSizes = new int[33]; Encoders = new PackedInts.Encoder[33]; Decoders = new PackedInts.Decoder[33]; Iterations = new int[33]; for (int bpv = 1; bpv <= 32; ++bpv) { var code = @in.ReadVInt(); var formatId = (int)((uint)code >> 5); var bitsPerValue = (code & 31) + 1; PackedInts.Format format = PackedInts.Format.ById(formatId); Debug.Assert(format.IsSupported(bitsPerValue)); EncodedSizes[bpv] = EncodedSize(format, packedIntsVersion, bitsPerValue); Encoders[bpv] = PackedInts.GetEncoder(format, packedIntsVersion, bitsPerValue); Decoders[bpv] = PackedInts.GetDecoder(format, packedIntsVersion, bitsPerValue); Iterations[bpv] = ComputeIterations(Decoders[bpv]); } }
internal PagedMutable(long size, int pageSize, int bitsPerValue, PackedInts.Format format) : base(bitsPerValue, size, pageSize) { this.Format = format; }