@Override public long getLong(int bits) { long value; if(bits <= bitsLeft) { // We can read from this word only // Shift to correct position and take only n least significant bits value = (lB >>> (bitsLeft - bits)) & LongArrayOutput.MASK_ARRAY[bits - 1]; bitsLeft -= bits; // We ate n bits from it checkAndFlipByte(); } else { // This word and next one, no more (max bits is 64) value = lB & LongArrayOutput.MASK_ARRAY[bitsLeft - 1]; // Read what's left first bits -= bitsLeft; flipByte(); // We need the next one value <<= bits; // Give n bits of space to value value |= (lB >>> (bitsLeft - bits)); bitsLeft -= bits; } return value; }
@Override public int nextClearBit(int maxBits) { int val = 0x00; for(int i = 0; i < maxBits; i++) { val <<= 1; // TODO This loop has too many branches and unnecessary boolean casts boolean bit = readBit(); if(bit) { val |= 0x01; } else { break; } } return val; } }
public List<WrappedGorillaDecompressor> getDecompressors(long begin, long end) { List<WrappedGorillaDecompressor> decompressors = new ArrayList<>(); long stamp = archivedCompressorLock.readLock(); try { for (WrappedGorillaCompressor r : archivedCompressors) { if (r.inRange(begin, end)) { GorillaDecompressor d = new GorillaDecompressor(new LongArrayInput(r.getCompressorOutput())); // use -1 length since this compressor is closed decompressors.add(new WrappedGorillaDecompressor(d, -1)); } } } finally { archivedCompressorLock.unlockRead(stamp); } // as long as begin is inRange, we should use the data in the current // compressor as well stamp = currentCompressorLock.readLock(); try { if (current != null && current.inRange(begin, end)) { LongArrayInput decompressorByteBufferInput = new LongArrayInput(current.getCompressorOutput()); GorillaDecompressor d = new GorillaDecompressor(decompressorByteBufferInput); WrappedGorillaDecompressor wd = new WrappedGorillaDecompressor(d, current.getNumEntries()); decompressors.add(wd); } } finally { currentCompressorLock.unlockRead(stamp); } return decompressors; }
private void checkAndFlipByte() { if(bitsLeft == 0) { flipByte(); } }
@Override public boolean readBit() { boolean bit = (lB & LongArrayOutput.BIT_SET_MASK[bitsLeft - 1]) != 0; bitsLeft--; checkAndFlipByte(); return bit; }
@Benchmark @OperationsPerInvocation(100000) public void decodingGorillaBenchmark(DataGenerator dg, Blackhole bh) throws Exception { LongArrayInput input = new LongArrayInput(dg.compressedArray); GorillaDecompressor d = new GorillaDecompressor(input); Pair pair; while((pair = d.readPair()) != null) { bh.consume(pair); } } }
private void checkAndFlipByte() { if(bitsLeft == 0) { flipByte(); } }
@Override public boolean readBit() { boolean bit = (lB & LongArrayOutput.BIT_SET_MASK[bitsLeft - 1]) != 0; bitsLeft--; checkAndFlipByte(); return bit; }
@Benchmark @OperationsPerInvocation(100000) public void decodingGorillaBenchmark(DataGenerator dg, Blackhole bh) throws Exception { LongArrayInput input = new LongArrayInput(dg.compressedArray); GorillaDecompressor d = new GorillaDecompressor(input); Pair pair; while((pair = d.readPair()) != null) { bh.consume(pair); } } }
@Override public long getLong(int bits) { long value; if(bits <= bitsLeft) { // We can read from this word only // Shift to correct position and take only n least significant bits value = (lB >>> (bitsLeft - bits)) & LongArrayOutput.MASK_ARRAY[bits - 1]; bitsLeft -= bits; // We ate n bits from it checkAndFlipByte(); } else { // This word and next one, no more (max bits is 64) value = lB & LongArrayOutput.MASK_ARRAY[bitsLeft - 1]; // Read what's left first bits -= bitsLeft; flipByte(); // We need the next one value <<= bits; // Give n bits of space to value value |= (lB >>> (bitsLeft - bits)); bitsLeft -= bits; } return value; }
public LongArrayInput(long[] array) { this.longArray = array; flipByte(); }
@Override public int nextClearBit(int maxBits) { int val = 0x00; for(int i = 0; i < maxBits; i++) { val <<= 1; // TODO This loop has too many branches and unnecessary boolean casts boolean bit = readBit(); if(bit) { val |= 0x01; } else { break; } } return val; } }
public LongArrayInput(long[] array) { this.longArray = array; flipByte(); }