diff --git a/.gitignore b/.gitignore index 02492f1..9d6e575 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,12 @@ hs_err_pid* .idea/ *.iml target/ + +# eclipse project file +.settings/ +.classpath +.project +.metadata + +# Maven +target/ diff --git a/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor.java b/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor.java index 2d69d96..e474bdb 100644 --- a/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor.java +++ b/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor.java @@ -12,6 +12,7 @@ public class Compressor { private int storedTrailingZeros = 0; private long storedVal = 0; private boolean first = true; + private int size; // public final static short FIRST_DELTA_BITS = 27; @@ -20,6 +21,7 @@ public class Compressor { // We should have access to the series? public Compressor(long timestamp, BitOutput output) { out = output; + size = 0; } /** @@ -54,6 +56,7 @@ private void writeFirst(long timestamp, long value) { first = false; storedVal = value; out.writeBits(storedVal, 64); + size += 64; } /** @@ -72,6 +75,7 @@ private void compressValue(long value) { if(xor == 0) { // Write 0 out.skipBit(); + size += 1; } else { int leadingZeros = Long.numberOfLeadingZeros(xor); int trailingZeros = Long.numberOfTrailingZeros(xor); @@ -83,6 +87,7 @@ private void compressValue(long value) { // Store bit '1' out.writeBit(); + size += 1; if(leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) { writeExistingLeading(xor); @@ -104,6 +109,7 @@ private void writeExistingLeading(long xor) { out.skipBit(); int significantBits = 64 - storedLeadingZeros - storedTrailingZeros; out.writeBits(xor >>> storedTrailingZeros, significantBits); + size += 1 + significantBits; } /** @@ -126,5 +132,11 @@ private void writeNewLeading(long xor, int leadingZeros, int trailingZeros) { storedLeadingZeros = leadingZeros; storedTrailingZeros = trailingZeros; + + size += 1 + 5 + 6 + significantBits; + } + + public int getSize() { + return size; } } diff --git a/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor32.java b/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor32.java index f929e38..4ca6991 100644 --- a/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor32.java +++ b/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor32.java @@ -12,14 +12,17 @@ public class Compressor32 { private int storedTrailingZeros = 0; private int storedVal = 0; private boolean first = true; + private int size; // public final static short FIRST_DELTA_BITS = 27; private BitOutput out; + // We should have access to the series? public Compressor32(long timestamp, BitOutput output) { out = output; + size = 0; } /** @@ -54,6 +57,7 @@ private void writeFirst(long timestamp, int value) { first = false; storedVal = value; out.writeBits(storedVal, 32); + size += 32; } /** @@ -72,6 +76,7 @@ private void compressValue(int value) { if(xor == 0) { // Write 0 out.skipBit(); + size += 1; } else { int leadingZeros = Integer.numberOfLeadingZeros(xor); int trailingZeros = Integer.numberOfTrailingZeros(xor); @@ -83,6 +88,7 @@ private void compressValue(int value) { // Store bit '1' out.writeBit(); + size += 1; if(leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) { writeExistingLeading(xor); @@ -104,6 +110,7 @@ private void writeExistingLeading(int xor) { out.skipBit(); int significantBits = 32 - storedLeadingZeros - storedTrailingZeros; out.writeBits(xor >>> storedTrailingZeros, significantBits); + size += 1 + significantBits; } /** @@ -126,5 +133,11 @@ private void writeNewLeading(int xor, int leadingZeros, int trailingZeros) { storedLeadingZeros = leadingZeros; storedTrailingZeros = trailingZeros; + + size += 1 + 5 + 6 + significantBits; + } + + public int getSize() { + return size; } } diff --git a/src/main/java/fi/iki/yak/ts/compression/gorilla/Decompressor32.java b/src/main/java/fi/iki/yak/ts/compression/gorilla/Decompressor32.java index cc402b9..c6fcb8c 100644 --- a/src/main/java/fi/iki/yak/ts/compression/gorilla/Decompressor32.java +++ b/src/main/java/fi/iki/yak/ts/compression/gorilla/Decompressor32.java @@ -16,8 +16,8 @@ public class Decompressor32 { private BitInput in; private final static int NAN_INT = 0x7fc00000; - - + + public Decompressor32(BitInput input) { in = input; } @@ -43,7 +43,7 @@ private void next() { endOfStream = true; return; } - + } else { nextValue(); } @@ -70,9 +70,9 @@ private void nextValue() { endOfStream = true; return; } else { - storedVal = value; + storedVal = value; } - + } } diff --git a/src/test/java/fi/iki/yak/ts/compression/gorilla/Encode32Test.java b/src/test/java/fi/iki/yak/ts/compression/gorilla/Encode32Test.java index e5b4e28..ae24e8e 100644 --- a/src/test/java/fi/iki/yak/ts/compression/gorilla/Encode32Test.java +++ b/src/test/java/fi/iki/yak/ts/compression/gorilla/Encode32Test.java @@ -26,6 +26,7 @@ private void comparePairsToCompression(long blockTimestamp, Pair32[] pairs) { Compressor32 c = new Compressor32(blockTimestamp, output); Arrays.stream(pairs).forEach(p -> c.addValue(p.getTimestamp(), p.getFloatValue())); c.close(); + System.out.println("Size: " + c.getSize()); ByteBuffer byteBuffer = output.getByteBuffer(); byteBuffer.flip(); @@ -52,9 +53,9 @@ void simpleEncodeAndDecodeTest() throws Exception { new Pair32(now + 10, Float.floatToRawIntBits((float) 1.0)), new Pair32(now + 20, Float.floatToRawIntBits((float) -2.0)), new Pair32(now + 28, Float.floatToRawIntBits((float) -2.5)), - new Pair32(now + 84, Float.floatToRawIntBits((float) 65537)), + new Pair32(now + 84, Float.floatToRawIntBits(65537)), new Pair32(now + 400, Float.floatToRawIntBits((float) 2147483650.0)), - new Pair32(now + 2300, Float.floatToRawIntBits((float) -16384)), + new Pair32(now + 2300, Float.floatToRawIntBits(-16384)), new Pair32(now + 16384, Float.floatToRawIntBits((float) 2.8)), new Pair32(now + 16500, Float.floatToRawIntBits((float) -38.0)), }; @@ -356,6 +357,7 @@ void testEncodeSimilarFloats() throws Exception { } c.close(); + System.out.println("Size: " + c.getSize()); bb.flip(); @@ -404,6 +406,7 @@ void testEncodeLargeAmountOfData() throws Exception { } c.close(); + System.out.println("Size: " + c.getSize()); bb.flip(); @@ -435,6 +438,7 @@ void testEmptyBlock() throws Exception { Compressor32 c = new Compressor32(now, output); c.close(); + System.out.println("Size: " + c.getSize()); ByteBuffer byteBuffer = output.getByteBuffer(); byteBuffer.flip(); @@ -470,6 +474,7 @@ void testLongEncoding() throws Exception { } c.close(); + System.out.println("Size: " + c.getSize()); bb.flip(); diff --git a/src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java b/src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java index 62654ea..fe30995 100644 --- a/src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java +++ b/src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java @@ -26,6 +26,7 @@ private void comparePairsToCompression(long blockTimestamp, Pair[] pairs) { Compressor c = new Compressor(blockTimestamp, output); Arrays.stream(pairs).forEach(p -> c.addValue(p.getTimestamp(), p.getDoubleValue())); c.close(); + System.out.println("Size: " + c.getSize()); ByteBuffer byteBuffer = output.getByteBuffer(); byteBuffer.flip(); @@ -356,6 +357,7 @@ void testEncodeSimilarFloats() throws Exception { } c.close(); + System.out.println("Size: " + c.getSize()); bb.flip(); @@ -404,6 +406,7 @@ void testEncodeLargeAmountOfData() throws Exception { } c.close(); + System.out.println("Size: " + c.getSize()); bb.flip(); @@ -435,6 +438,7 @@ void testEmptyBlock() throws Exception { Compressor c = new Compressor(now, output); c.close(); + System.out.println("Size: " + c.getSize()); ByteBuffer byteBuffer = output.getByteBuffer(); byteBuffer.flip(); @@ -470,6 +474,7 @@ void testLongEncoding() throws Exception { } c.close(); + System.out.println("Size: " + c.getSize()); bb.flip();