void addValueIntoHighBits(long value) { currentHighBit += value; int longIndex = (int) (currentHighBit >> 6); int bitIndex = (int) (currentHighBit & 0x3F); long l = highBits.get(longIndex); highBits.set(longIndex, l | (1L << bitIndex)); currentHighBit++; }
public long get(int index) { long highBit = skipIndex[(index >>> 7) * 2]; long previousValue = skipIndex[((index >>> 7) * 2) + 1]; long highBitValue = previousValue >> numLowBits; int currentHighBitLongIndex = (int) (highBit >>> 6); int currentHighBitBitIndex = (int) (highBit & 0x3F); int numBitsToRead = index & 0x7F; long curVal = highBits.get(currentHighBitLongIndex); curVal >>>= currentHighBitBitIndex; int bitCount = Long.bitCount(curVal); while (numBitsToRead >= bitCount) { highBitValue += 64 - currentHighBitBitIndex - bitCount; numBitsToRead -= bitCount; currentHighBitBitIndex = 0; currentHighBitLongIndex++; curVal = highBits.get(currentHighBitLongIndex); bitCount = Long.bitCount(curVal); } int encodedHighBitValue = 0; for (int i = 0; i <= numBitsToRead; i++) { encodedHighBitValue = Long.numberOfTrailingZeros(curVal); highBitValue += encodedHighBitValue; curVal >>>= encodedHighBitValue + 1; } long lowBitData = getLowBits(index); if (lowBitData == 0 && encodedHighBitValue == 0 && (numBitsToRead != 0 || currentHighBitBitIndex != 0 || (currentHighBitLongIndex == 0 || highBits.get(currentHighBitLongIndex - 1) < 0))) { return -1; } return (highBitValue << numLowBits) | lowBitData; }