/** * store the length of the number of leading zeros in the next 5 bits * store length of the meaningful XORed value in the next 6 bits, * store the meaningful bits of the XORed value * (type b) * * @param xor XOR between previous value and current * @param leadingZeros New leading zeros * @param trailingZeros New trailing zeros */ private void writeNewLeading(long xor, int leadingZeros, int trailingZeros) { out.writeBit(); out.writeBits(leadingZeros, 5); // Number of leading zeros in the next 5 bits int significantBits = 64 - leadingZeros - trailingZeros; out.writeBits(significantBits, 6); // Length of meaningful bits in the next 6 bits out.writeBits(xor >>> trailingZeros, significantBits); // Store the meaningful bits of XOR storedLeadingZeros = leadingZeros; storedTrailingZeros = trailingZeros; } }
/** * If there at least as many leading zeros and as many trailing zeros as previous value, control bit = 0 (type a) * store the meaningful XORed value * * @param xor XOR between previous value and current */ private void writeExistingLeading(long xor) { out.skipBit(); int significantBits = 64 - storedLeadingZeros - storedTrailingZeros; xor >>>= storedTrailingZeros; out.writeBits(xor, significantBits); }
private void compressValue(long value) { // TODO Fix already compiled into a big method long xor = storedVal ^ value; if(xor == 0) { // Write 0 out.skipBit(); } else { int leadingZeros = Long.numberOfLeadingZeros(xor); int trailingZeros = Long.numberOfTrailingZeros(xor); // Check overflow of leading? Can't be 32! if(leadingZeros >= 32) { leadingZeros = 31; } // Store bit '1' out.writeBit(); if(leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) { writeExistingLeading(xor); } else { writeNewLeading(xor, leadingZeros, trailingZeros); } } storedVal = value; }
/** * If there at least as many leading zeros and as many trailing zeros as previous value, control bit = 0 (type a) * store the meaningful XORed value * * @param xor XOR between previous value and current */ private void writeExistingLeading(long xor) { out.skipBit(); int significantBits = 64 - storedLeadingZeros - storedTrailingZeros; xor >>>= storedTrailingZeros; out.writeBits(xor, significantBits); }
private void compressValue(long value) { // TODO Fix already compiled into a big method long xor = storedVal ^ value; if(xor == 0) { // Write 0 out.skipBit(); } else { int leadingZeros = Long.numberOfLeadingZeros(xor); int trailingZeros = Long.numberOfTrailingZeros(xor); // Check overflow of leading? Can't be 32! if(leadingZeros >= 32) { leadingZeros = 31; } // Store bit '1' out.writeBit(); if(leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) { writeExistingLeading(xor); } else { writeNewLeading(xor, leadingZeros, trailingZeros); } } storedVal = value; }
/** * If there at least as many leading zeros and as many trailing zeros as previous value, control bit = 0 (type a) * store the meaningful XORed value * * @param xor XOR between previous value and current */ private void writeExistingLeading(long xor) { out.skipBit(); int significantBits = 64 - storedLeadingZeros - storedTrailingZeros; out.writeBits(xor >>> storedTrailingZeros, significantBits); }
protected void compressValue(long value) { // In original Gorilla, Last-Value predictor is used long diff = predictor.predict() ^ value; predictor.update(value); if(diff == 0) { // Write 0 out.skipBit(); } else { int leadingZeros = Long.numberOfLeadingZeros(diff); int trailingZeros = Long.numberOfTrailingZeros(diff); out.writeBit(); // Optimize to writeNewLeading / writeExistingLeading? if(leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) { writeExistingLeading(diff); } else { writeNewLeading(diff, leadingZeros, trailingZeros); } } }
/** * store the length of the number of leading zeros in the next 5 bits * store length of the meaningful XORed value in the next 6 bits, * store the meaningful bits of the XORed value * (type b) * * @param xor XOR between previous value and current * @param leadingZeros New leading zeros * @param trailingZeros New trailing zeros */ private void writeNewLeading(long xor, int leadingZeros, int trailingZeros) { out.writeBit(); out.writeBits(leadingZeros, 5); // Number of leading zeros in the next 5 bits int significantBits = 64 - leadingZeros - trailingZeros; out.writeBits(significantBits, 6); // Length of meaningful bits in the next 6 bits out.writeBits(xor >>> trailingZeros, significantBits); // Store the meaningful bits of XOR storedLeadingZeros = leadingZeros; storedTrailingZeros = trailingZeros; } }
private void addHeader(long timestamp) { // One byte: length of the first delta // One byte: precision of timestamps out.writeBits(timestamp, 64); }
/** * If there at least as many leading zeros and as many trailing zeros as previous value, control bit = 0 (type a) * store the meaningful XORed value * * @param xor XOR between previous value and current */ private void writeExistingLeading(long xor) { out.skipBit(); int significantBits = 64 - storedLeadingZeros - storedTrailingZeros; out.writeBits(xor >>> storedTrailingZeros, significantBits); }
protected void compressValue(long value) { // In original Gorilla, Last-Value predictor is used long diff = predictor.predict() ^ value; predictor.update(value); if(diff == 0) { // Write 0 out.skipBit(); } else { int leadingZeros = Long.numberOfLeadingZeros(diff); int trailingZeros = Long.numberOfTrailingZeros(diff); out.writeBit(); // Optimize to writeNewLeading / writeExistingLeading? if(leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) { writeExistingLeading(diff); } else { writeNewLeading(diff, leadingZeros, trailingZeros); } } }
/** * store the length of the number of leading zeros in the next 5 bits * store length of the meaningful XORed value in the next 6 bits, * store the meaningful bits of the XORed value * (type b) * * @param xor XOR between previous value and current * @param leadingZeros New leading zeros * @param trailingZeros New trailing zeros */ private void writeNewLeading(long xor, int leadingZeros, int trailingZeros) { out.writeBit(); // Different from version 1.x, use (significantBits - 1) in storage - avoids a branch int significantBits = 64 - leadingZeros - trailingZeros; // Different from original, bits 5 -> 6, avoids a branch, allows storing small longs out.writeBits(leadingZeros, 6); // Number of leading zeros in the next 6 bits out.writeBits(significantBits - 1, 6); // Length of meaningful bits in the next 6 bits out.writeBits(xor >>> trailingZeros, significantBits); // Store the meaningful bits of XOR storedLeadingZeros = leadingZeros; storedTrailingZeros = trailingZeros; } }
private void addHeader(long timestamp) { // One byte: length of the first delta // One byte: precision of timestamps out.writeBits(timestamp, 64); }
out.skipBit(); } else if(deltaD >= -63 && deltaD <= 64) { out.writeBits(0x02, 2); // store '10' out.writeBits(deltaD, 7); // Using 7 bits, store the value.. } else if(deltaD >= -255 && deltaD <= 256) { out.writeBits(0x06, 3); // store '110' out.writeBits(deltaD, 9); // Use 9 bits } else if(deltaD >= -2047 && deltaD <= 2048) { out.writeBits(0x0E, 4); // store '1110' out.writeBits(deltaD, 12); // Use 12 bits } else { out.writeBits(0x0F, 4); // Store '1111' out.writeBits(deltaD, 32); // Store delta using 32 bits