private NumericDocValues LoadShortField(FieldInfo field, IndexInput input) { CodecUtil.CheckHeader(input, Lucene40DocValuesFormat.INTS_CODEC_NAME, Lucene40DocValuesFormat.INTS_VERSION_START, Lucene40DocValuesFormat.INTS_VERSION_CURRENT); int valueSize = input.ReadInt(); if (valueSize != 2) { throw new CorruptIndexException("invalid valueSize: " + valueSize); } int maxDoc = State.SegmentInfo.DocCount; short[] values = new short[maxDoc]; for (int i = 0; i < values.Length; i++) { values[i] = input.ReadShort(); } RamBytesUsed_Renamed.AddAndGet(RamUsageEstimator.SizeOf(values)); return new NumericDocValuesAnonymousInnerClassHelper4(values); }
public override long Get(int index) { long majorBitPos = (long)index * bitsPerValue; long elementPos = (long)((ulong)majorBitPos >> 3); try { @in.Seek(StartPointer + elementPos); int bitPos = (int)(majorBitPos & 7); // round up bits to a multiple of 8 to find total bytes needed to read int roundedBits = ((bitPos + bitsPerValue + 7) & ~7); // the number of extra bits read at the end to shift out int shiftRightBits = roundedBits - bitPos - bitsPerValue; long rawValue; switch ((int)((uint)roundedBits >> 3)) { case 1: rawValue = @in.ReadByte(); break; case 2: rawValue = @in.ReadShort(); break; case 3: rawValue = ((long)@in.ReadShort() << 8) | (@in.ReadByte() & 0xFFL); break; case 4: rawValue = @in.ReadInt(); break; case 5: rawValue = ((long)@in.ReadInt() << 8) | (@in.ReadByte() & 0xFFL); break; case 6: rawValue = ((long)@in.ReadInt() << 16) | (@in.ReadShort() & 0xFFFFL); break; case 7: rawValue = ((long)@in.ReadInt() << 24) | ((@in.ReadShort() & 0xFFFFL) << 8) | (@in.ReadByte() & 0xFFL); break; case 8: rawValue = @in.ReadLong(); break; case 9: // We must be very careful not to shift out relevant bits. So we account for right shift // we would normally do on return here, and reset it. rawValue = (@in.ReadLong() << (8 - shiftRightBits)) | ((int)((uint)(@in.ReadByte() & 0xFFL) >> shiftRightBits)); shiftRightBits = 0; break; default: throw new InvalidOperationException("bitsPerValue too large: " + bitsPerValue); } return(((long)((ulong)rawValue >> shiftRightBits)) & ValueMask); } catch (System.IO.IOException ioe) { throw new InvalidOperationException("failed", ioe); } }