Skip to content

Commit

Permalink
added 32-bit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
panagiotisl committed Mar 12, 2022
1 parent 99eeb0a commit 93d9c56
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ hs_err_pid*
.idea/
*.iml
target/

# eclipse project file
.settings/
.classpath
.project
.metadata

# Maven
target/
12 changes: 12 additions & 0 deletions src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,6 +21,7 @@ public class Compressor {
// We should have access to the series?
public Compressor(long timestamp, BitOutput output) {
out = output;
size = 0;
}

/**
Expand Down Expand Up @@ -54,6 +56,7 @@ private void writeFirst(long timestamp, long value) {
first = false;
storedVal = value;
out.writeBits(storedVal, 64);
size += 64;
}

/**
Expand All @@ -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);
Expand All @@ -83,6 +87,7 @@ private void compressValue(long value) {

// Store bit '1'
out.writeBit();
size += 1;

if(leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) {
writeExistingLeading(xor);
Expand All @@ -104,6 +109,7 @@ private void writeExistingLeading(long xor) {
out.skipBit();
int significantBits = 64 - storedLeadingZeros - storedTrailingZeros;
out.writeBits(xor >>> storedTrailingZeros, significantBits);
size += 1 + significantBits;
}

/**
Expand All @@ -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;
}
}
13 changes: 13 additions & 0 deletions src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor32.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -54,6 +57,7 @@ private void writeFirst(long timestamp, int value) {
first = false;
storedVal = value;
out.writeBits(storedVal, 32);
size += 32;
}

/**
Expand All @@ -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);
Expand All @@ -83,6 +88,7 @@ private void compressValue(int value) {

// Store bit '1'
out.writeBit();
size += 1;

if(leadingZeros >= storedLeadingZeros && trailingZeros >= storedTrailingZeros) {
writeExistingLeading(xor);
Expand All @@ -104,6 +110,7 @@ private void writeExistingLeading(int xor) {
out.skipBit();
int significantBits = 32 - storedLeadingZeros - storedTrailingZeros;
out.writeBits(xor >>> storedTrailingZeros, significantBits);
size += 1 + significantBits;
}

/**
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class Decompressor32 {
private BitInput in;

private final static int NAN_INT = 0x7fc00000;


public Decompressor32(BitInput input) {
in = input;
}
Expand All @@ -43,7 +43,7 @@ private void next() {
endOfStream = true;
return;
}

} else {
nextValue();
}
Expand All @@ -70,9 +70,9 @@ private void nextValue() {
endOfStream = true;
return;
} else {
storedVal = value;
storedVal = value;
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)),
};
Expand Down Expand Up @@ -356,6 +357,7 @@ void testEncodeSimilarFloats() throws Exception {
}

c.close();
System.out.println("Size: " + c.getSize());

bb.flip();

Expand Down Expand Up @@ -404,6 +406,7 @@ void testEncodeLargeAmountOfData() throws Exception {
}

c.close();
System.out.println("Size: " + c.getSize());

bb.flip();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -470,6 +474,7 @@ void testLongEncoding() throws Exception {
}

c.close();
System.out.println("Size: " + c.getSize());

bb.flip();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -356,6 +357,7 @@ void testEncodeSimilarFloats() throws Exception {
}

c.close();
System.out.println("Size: " + c.getSize());

bb.flip();

Expand Down Expand Up @@ -404,6 +406,7 @@ void testEncodeLargeAmountOfData() throws Exception {
}

c.close();
System.out.println("Size: " + c.getSize());

bb.flip();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -470,6 +474,7 @@ void testLongEncoding() throws Exception {
}

c.close();
System.out.println("Size: " + c.getSize());

bb.flip();

Expand Down

0 comments on commit 93d9c56

Please sign in to comment.