public long[] getCompressorOutput() { if (closed) { return backingArray; } else { return compressorOutput.getLongArray(); } }
protected void flipWord() { if(capacityLeft() <= 2) { // We want to have always at least 2 longs available expandAllocation(); } flipWordWithoutExpandCheck(); }
/** * Writes the given long to the stream using bits amount of meaningful bits. This command does not * check input values, so if they're larger than what can fit the bits (you should check this before writing), * expect some weird results. * * @param value Value to be written to the stream * @param bits How many bits are stored to the stream */ public void writeBits(long value, int bits) { if(bits <= bitsLeft) { int lastBitPosition = bitsLeft - bits; lB |= (value << lastBitPosition) & MASK_ARRAY[bitsLeft - 1]; bitsLeft -= bits; checkAndFlipByte(); // We could be at 0 bits left because of the <= condition .. would it be faster with // the other one? } else { value &= MASK_ARRAY[bits - 1]; int firstBitPosition = bits - bitsLeft; lB |= value >>> firstBitPosition; bits -= bitsLeft; flipWord(); lB |= value << (64 - bits); bitsLeft -= bits; } }
LongArrayOutput arrayOutput = new LongArrayOutput(amountOfPoints); compressedBuffer = byteBuffer; compressedArray = arrayOutput.getLongArray();
public WrappedGorillaCompressor(long timestamp) { this.compressorOutput = new LongArrayOutput(16); this.compressor = new GorillaCompressor(timestamp, this.compressorOutput); this.oldestTimestamp = timestamp; this.newestTimestamp = timestamp; }
private void checkAndFlipByte() { // Wish I could avoid this check in most cases... if(bitsLeft == 0) { flipWord(); } }
/** * Sets the next bit (or not) and moves the bit pointer. */ public void writeBit() { lB |= BIT_SET_MASK[bitsLeft - 1]; bitsLeft--; checkAndFlipByte(); }
protected void flipWordWithoutExpandCheck() { longArray[position] = lB; ++position; resetInternalWord(); }
LongArrayOutput arrayOutput = new LongArrayOutput(amountOfPoints); compressedBuffer = byteBuffer; compressedArray = arrayOutput.getLongArray();
@Benchmark @OperationsPerInvocation(100000) public void encodingGorillaBenchmark(DataGenerator dg) { LongArrayOutput output = new LongArrayOutput(); GorillaCompressor c = new GorillaCompressor(dg.blockStart, output); for(int j = 0; j < dg.amountOfPoints; j++) { c.addValue(dg.uncompressedTimestamps[j], dg.uncompressedDoubles[j]); } c.close(); }
/** * Causes the currently handled word to be written to the stream */ @Override public void flush() { flipWord(); }
public void skipBit() { bitsLeft--; checkAndFlipByte(); }
protected void flipWordWithoutExpandCheck() { longArray[position] = lB; ++position; resetInternalWord(); }
@Benchmark @OperationsPerInvocation(100000) public void encodingGorillaBenchmarkLong(DataGenerator dg) { LongArrayOutput output = new LongArrayOutput(); GorillaCompressor c = new GorillaCompressor(dg.blockStart, output); for(int j = 0; j < dg.amountOfPoints; j++) { c.addValue(dg.uncompressedTimestamps[j], dg.uncompressedValues[j]); } c.close(); }
protected void flipWord() { if(capacityLeft() <= 2) { // We want to have always at least 2 longs available expandAllocation(); } flipWordWithoutExpandCheck(); }
public void close() { compressor.close(); backingArray = compressorOutput.getLongArray(); compressorOutput = null; closed = true; }
/** * Writes the given long to the stream using bits amount of meaningful bits. This command does not * check input values, so if they're larger than what can fit the bits (you should check this before writing), * expect some weird results. * * @param value Value to be written to the stream * @param bits How many bits are stored to the stream */ public void writeBits(long value, int bits) { if(bits <= bitsLeft) { int lastBitPosition = bitsLeft - bits; lB |= (value << lastBitPosition) & MASK_ARRAY[bitsLeft - 1]; bitsLeft -= bits; checkAndFlipByte(); // We could be at 0 bits left because of the <= condition .. would it be faster with // the other one? } else { value &= MASK_ARRAY[bits - 1]; int firstBitPosition = bits - bitsLeft; lB |= value >>> firstBitPosition; bits -= bitsLeft; flipWord(); lB |= value << (64 - bits); bitsLeft -= bits; } }
/** * Causes the currently handled word to be written to the stream */ @Override public void flush() { flipWord(); }
public void skipBit() { bitsLeft--; checkAndFlipByte(); }
@Benchmark @OperationsPerInvocation(100000) public void encodingGorillaBenchmark(DataGenerator dg) { LongArrayOutput output = new LongArrayOutput(); GorillaCompressor c = new GorillaCompressor(dg.blockStart, output); for(int j = 0; j < dg.amountOfPoints; j++) { c.addValue(dg.uncompressedTimestamps[j], dg.uncompressedDoubles[j]); } c.close(); }