diff --git a/pom.xml b/pom.xml
index 65d6754..0d018d4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -132,8 +132,7 @@
0.7.6.201602180812
- com/kamikaze/pfordelta/*
- me/lemire/integercompression/benchmarktools/*
+ ../../../test/java/*
diff --git a/src/test/java/com/kamikaze/pfordelta/PForDeltaUnpack128Test.java b/src/test/java/com/kamikaze/pfordelta/PForDeltaUnpack128Test.java
new file mode 100644
index 0000000..f0ad04a
--- /dev/null
+++ b/src/test/java/com/kamikaze/pfordelta/PForDeltaUnpack128Test.java
@@ -0,0 +1,32 @@
+package com.kamikaze.pfordelta;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Created by xueli on 12/8/16.
+ */
+public class PForDeltaUnpack128Test {
+ PForDeltaUnpack128 sm = new PForDeltaUnpack128();
+
+ @Test
+ public void test(){
+ int[] input = new int[1024];
+ int[] output = new int[1024];
+
+ for (int k = 0; k < 1024; ++k) input[k] = k;
+
+ for(int i = 0; i < 29; i++){
+
+ //int i = j << 28;
+
+ sm.unpack(output, input, i);
+
+
+ }
+
+
+
+ }
+}
diff --git a/src/test/java/com/kamikaze/pfordelta/PForDeltaUnpack128WithIntBufferTest.java b/src/test/java/com/kamikaze/pfordelta/PForDeltaUnpack128WithIntBufferTest.java
new file mode 100644
index 0000000..bc9fef3
--- /dev/null
+++ b/src/test/java/com/kamikaze/pfordelta/PForDeltaUnpack128WithIntBufferTest.java
@@ -0,0 +1,41 @@
+package com.kamikaze.pfordelta;
+
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+
+/**
+ * Created by xueli on 12/8/16.
+ */
+public class PForDeltaUnpack128WithIntBufferTest {
+ PForDeltaUnpack128WIthIntBuffer sm = new PForDeltaUnpack128WIthIntBuffer();
+
+ byte[] buf = new byte[4096];
+ ByteBuffer bufWrap = ByteBuffer.wrap(buf);
+
+ IntBuffer ibuf = bufWrap.asIntBuffer();
+
+
+ @Test
+ public void test(){
+
+ //int[] input = new int[1024];
+ int[] output = new int[256];
+
+ //for (int k = 0; k < 1024; ++k) input[k] = k;
+
+ for(int i = 0; i < 29; i++){
+
+ //int i = j << 28;
+
+ sm.unpack(output, ibuf, i);
+
+
+ }
+
+
+
+ }
+}
diff --git a/src/test/java/com/kamikaze/pfordelta/Simple16WithHardCodesTest.java b/src/test/java/com/kamikaze/pfordelta/Simple16WithHardCodesTest.java
new file mode 100644
index 0000000..2c3a381
--- /dev/null
+++ b/src/test/java/com/kamikaze/pfordelta/Simple16WithHardCodesTest.java
@@ -0,0 +1,56 @@
+package com.kamikaze.pfordelta;
+
+import org.junit.Test;
+import com.kamikaze.*;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Created by xueli on 12/8/16.
+ */
+public class Simple16WithHardCodesTest {
+ Simple16WithHardCodes sm = new Simple16WithHardCodes();
+
+ @Test
+ public void test(){
+ int[] input = new int[1024];
+ int[] output = new int[1024];
+
+ for (int k = 0; k < 1024; ++k) input[k] = k;
+ int k = sm.s16Compress(output, 0, input, 0, 1024, 10, 10, input);
+ assertEquals(k, 8);
+
+ assertEquals(sm.s16CompressBackup(output, 0, input, 0, 1024, 10, 10, input), 8);
+
+ assertEquals(sm.s16Decompress(output, 0, input, 0, 1024), 28);
+
+
+
+
+
+ for(int j = 0; j < 17; j++){
+
+ int i = j << 28;
+
+ sm.s16DecompressWithIntBufferBackup(output, 0, i, 0);
+
+ sm.s16DecompressWithIntBuffer(output, 0, i, 0);
+
+ sm.s16DecompressWithIntBufferWithHardCodes(output, 0, i, 0);
+
+ sm.s16DecompressWithIntBufferIntegrated(output, 0, i, 0, input, 8);
+
+
+ sm.s16DecompressWithIntBufferIntegrated2(output, 0, i, 0, input, 8);
+
+ sm.s16DecompressWithIntBufferIntegratedBackup(output, 0, i, 0, input, 8);
+
+ sm.s16DecompressOneNumberWithHardCodes(output, 0, i, 0);
+
+ sm.s16DecompressOneNumberWithHardCodesIntegrated(output, 0, i, 0, 8, input);
+ }
+
+
+
+ }
+}
diff --git a/src/test/java/me/lemire/integercompression/BasicTest.java b/src/test/java/me/lemire/integercompression/BasicTest.java
index cbdb60e..e5ffb30 100644
--- a/src/test/java/me/lemire/integercompression/BasicTest.java
+++ b/src/test/java/me/lemire/integercompression/BasicTest.java
@@ -245,10 +245,15 @@ public void verifyBitPacking() {
int[] data = new int[N];
int[] compressed = new int[N];
int[] uncompressed = new int[N];
- for (int bit = 0; bit < 31; ++bit) {
+ for (int bit = 0; bit < 32; ++bit) {//Xue
for (int t = 0; t < TIMES; ++t) {
for (int k = 0; k < N; ++k) {
- data[k] = r.nextInt(1 << bit);
+ if(bit == 31){
+ data[k] = r.nextInt(1 << 30);
+ }
+ else {
+ data[k] = r.nextInt(1 << bit);
+ }
}
BitPacking.fastpack(data, 0, compressed, 0, bit);
BitPacking.fastunpack(compressed, 0, uncompressed, 0, bit);
@@ -268,10 +273,15 @@ public void verifyWithoutMask() {
int[] data = new int[N];
int[] compressed = new int[N];
int[] uncompressed = new int[N];
- for (int bit = 0; bit < 31; ++bit) {
+ for (int bit = 0; bit < 32; ++bit) {//Xue
for (int t = 0; t < TIMES; ++t) {
for (int k = 0; k < N; ++k) {
- data[k] = r.nextInt(1 << bit);
+ if(bit == 31){
+ data[k] = r.nextInt(1 << 30);
+ }
+ else {
+ data[k] = r.nextInt(1 << bit);
+ }
}
BitPacking.fastpackwithoutmask(data, 0, compressed, 0, bit);
BitPacking.fastunpack(compressed, 0, uncompressed, 0, bit);
diff --git a/src/test/java/me/lemire/integercompression/DeltaTest.java b/src/test/java/me/lemire/integercompression/DeltaTest.java
new file mode 100644
index 0000000..073fb54
--- /dev/null
+++ b/src/test/java/me/lemire/integercompression/DeltaTest.java
@@ -0,0 +1,93 @@
+package me.lemire.integercompression;
+
+import me.lemire.integercompression.differential.Delta;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Tests for class Delta.
+ *
+ * @author Xue Li
+ */
+@SuppressWarnings({ "static-method" })
+public class DeltaTest {
+
+ /**
+ *
+ */
+ @Test
+ public void simpleDeltaTest() {
+
+ int[] data = new int[1024];
+
+ for (int k = 0; k < 1024; ++k) data[k] = k;
+
+ Delta.delta(data);
+
+ for (int k = 1; k < 1024; ++k){
+ assertEquals("simple delta", data[k], 1);
+ }
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void deltaWithInitialTest() {
+ int[] data = new int[1024]; //0 1 2 3 4 5 6 7 8 9 10 ... => 0 1 2 -5 1 1 1 1 8 9 10, return 7
+
+ int start = 3, length = 5, init;
+ int[] out = new int[length];
+
+ for (int k = 0; k < 1024; ++k) data[k] = k;
+ init = data[start - 1];
+
+ Delta.delta(data, start, length, init, out);
+
+ for (int k = 0; k < length; ++k){
+ assertEquals("deltaWithInitialTest", out[k], 1);
+ }
+ }
+
+ @Test
+ public void inverseDeltaTest(){
+ int[] data = new int[1024];
+
+ for (int k = 0; k < 1024; ++k) data[k] = k;
+
+ Delta.delta(data);
+ Delta.inverseDelta(data);
+
+ for (int k = 0; k < 1024; ++k){
+ assertEquals("inverseDeltaTest", data[k], k);
+ }
+ }
+
+ @Test
+ public void fastinverseDeltaTest(){
+ int[] data = new int[1024];
+
+ for (int k = 0; k < 1024; ++k) data[k] = k;
+
+ Delta.delta(data);
+ Delta.fastinverseDelta(data);
+
+ for (int k = 0; k < 1024; ++k){
+ assertEquals("inverseDeltaTest", data[k], k);
+ }
+ }
+
+ @Test
+ public void fastinverseDeltaWithInitialTest(){
+ int[] data = {0, 1, 2, 1, 1, 1, 1, 1, 8, 9}; //0 1 2 3 4 5 6 7 8 9 10 ... => 0 1 2 -5 1 1 1 1 8 9 10, return 7
+ int start = 3, length = 5, init = 2;
+
+ Delta.fastinverseDelta(data, start, length, init);
+
+ for (int k = 0; k < length; ++k){
+ assertEquals("fastinverseDeltaWithInitialTest", data[k], k);
+ }
+ }
+}
diff --git a/src/test/java/me/lemire/integercompression/GroupSimpleTest.java b/src/test/java/me/lemire/integercompression/GroupSimpleTest.java
new file mode 100644
index 0000000..91c864c
--- /dev/null
+++ b/src/test/java/me/lemire/integercompression/GroupSimpleTest.java
@@ -0,0 +1,162 @@
+package me.lemire.integercompression;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+
+
+/**
+ * Tests for class GroupSimple9.
+ *
+ * @author Xue Li
+ */
+@SuppressWarnings({ "static-method" })
+public class GroupSimpleTest {
+ SkippableIntegerCODEC[] codecs = {
+ new GroupSimple9()
+ };
+
+
+ /**
+ *
+ */
+ @Test
+ public void consistentTest() {
+ int bitLength[] = { 1, 2, 3, 4, 5, 7, 9, 14, 28 };
+ int codeNum[] = { 28, 14, 9, 7, 5, 4, 3, 2, 1 };
+ for(int s1 = 0 ; s1 < 9; ++s1){
+ for(int s2 = 0; s2 < 9; ++s2){
+ int max1 = 1 << bitLength[s1];
+ int max2 = 1 << bitLength[s2];
+ int num1 = codeNum[s1];
+ int num2 = codeNum[s2];
+
+ int N = num1 + num2;
+ if(N < 57) N = 57;
+ int[] data = new int[N];
+
+ int i = 0;
+ for(; i < num1; ++i){
+ data[i] = max1 - 1;
+ }
+ for(; i < N; ++i){
+ data[i] = max2 - 1;
+ }
+
+ oneTest(N, data);
+
+ }
+ }
+
+
+ }
+ private void oneTest(int N, int[] data){
+ int[] rev = new int[N];
+
+ //for (int k = 0; k < N; ++k)
+ // data[k] = k % 128;
+ for (SkippableIntegerCODEC c : codecs) {
+ System.out.println("[SkippeableBasicTest.consistentTest] codec = "
+ + c);
+ int[] outBuf = new int[N + 1024];
+ for (int n = 0; n <= N; ++n) {
+ IntWrapper inPos = new IntWrapper();
+ IntWrapper outPos = new IntWrapper();
+ c.headlessCompress(data, inPos, n, outBuf, outPos);
+
+ IntWrapper inPoso = new IntWrapper();
+ IntWrapper outPoso = new IntWrapper();
+ c.headlessUncompress(outBuf, inPoso, outPos.get(), rev,
+ outPoso, n);
+ if (outPoso.get() != n) {
+ throw new RuntimeException("bug "+n);
+ }
+ if (inPoso.get() != outPos.get()) {
+ throw new RuntimeException("bug "+n+" "+inPoso.get()+" "+outPos.get());
+ }
+ for (int j = 0; j < n; ++j)
+ if (data[j] != rev[j]) {
+ throw new RuntimeException("bug");
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void varyingLengthTest() {
+ int N = 4096;
+ int[] data = new int[N];
+ for (int k = 0; k < N; ++k)
+ data[k] = k;
+ for (SkippableIntegerCODEC c : codecs) {
+ System.out.println("[SkippeableBasicTest.varyingLengthTest] codec = "+c);
+ for (int L = 1; L <= 128; L++) {
+ int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
+ int[] answer = TestUtils.uncompressHeadless(c, comp, L);
+ for (int k = 0; k < L; ++k)
+ if (answer[k] != data[k])
+ throw new RuntimeException("bug "+c.toString()+" "+k+" "+answer[k]+" "+data[k]);
+ }
+ for (int L = 128; L <= N; L *= 2) {
+ int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
+ int[] answer = TestUtils.uncompressHeadless(c, comp, L);
+ for (int k = 0; k < L; ++k)
+ if (answer[k] != data[k])
+ throw new RuntimeException("bug");
+ }
+
+ }
+ }
+
+ /**
+ *
+ */
+ /*
+ @Test
+
+ public void varyingLengthTest2() {
+ int N = 128;
+ int[] data = new int[N];
+ data[127] = -1;
+ for (SkippableIntegerCODEC c : codecs) {
+ System.out.println("[SkippeableBasicTest.varyingLengthTest2] codec = "+c);
+
+ try {
+ // CODEC Simple9 is limited to "small" integers.
+ if (c.getClass().equals(
+ Class.forName("me.lemire.integercompression.Simple9")))
+ continue;
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ try {
+ // CODEC Simple16 is limited to "small" integers.
+ if (c.getClass().equals(
+ Class.forName("me.lemire.integercompression.Simple16")))
+ continue;
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ for (int L = 1; L <= 128; L++) {
+ int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
+ int[] answer = TestUtils.uncompressHeadless(c, comp, L);
+ for (int k = 0; k < L; ++k)
+ if (answer[k] != data[k])
+ throw new RuntimeException("bug at k = "+k+" "+answer[k]+" "+data[k]+" for "+c.toString());
+ }
+ for (int L = 128; L <= N; L *= 2) {
+ int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
+ int[] answer = TestUtils.uncompressHeadless(c, comp, L);
+ for (int k = 0; k < L; ++k)
+ if (answer[k] != data[k])
+ throw new RuntimeException("bug");
+ }
+
+ }
+ }
+
+ */
+}
diff --git a/src/test/java/me/lemire/integercompression/IntegratedBitPackingTest.java b/src/test/java/me/lemire/integercompression/IntegratedBitPackingTest.java
new file mode 100644
index 0000000..d45e697
--- /dev/null
+++ b/src/test/java/me/lemire/integercompression/IntegratedBitPackingTest.java
@@ -0,0 +1,152 @@
+package me.lemire.integercompression;
+
+import me.lemire.integercompression.differential.Delta;
+import me.lemire.integercompression.differential.IntegratedBitPacking;
+import org.junit.Test;
+
+import java.text.DecimalFormat;
+import java.util.Arrays;
+import java.util.Random;
+
+
+/**
+ * Tests for class GroupSimple9.
+ *
+ * @author Xue Li
+ */
+@SuppressWarnings({ "static-method" })
+public class IntegratedBitPackingTest {
+
+
+ /**
+ *
+ */
+ @Test
+ public void Test() {
+ testCore(true);
+ }
+ private void testCore(boolean verbose) {
+ DecimalFormat dfspeed = new DecimalFormat("0");
+ final int N = 32;
+ final int times = 100000;
+ Random r = new Random(0);
+ int[] data = new int[N];
+ int[] compressed = new int[N];
+ int[] uncompressed = new int[N];
+ for (int bit = 0; bit < 32; ++bit) {
+ long comp = 0;
+ long compwm = 0;
+ long decomp = 0;
+ for (int t = 0; t < times; ++t) {
+ for (int k = 0; k < N; ++k) {
+ data[k] = r.nextInt(1 << (bit == 31 ? 30 : bit));
+ }
+ long time1 = System.nanoTime();
+ BitPacking
+ .fastpack(data, 0, compressed, 0, bit);
+ long time2 = System.nanoTime();
+ BitPacking.fastpackwithoutmask(data, 0,
+ compressed, 0, bit);
+ long time3 = System.nanoTime();
+ BitPacking.fastunpack(compressed, 0,
+ uncompressed, 0, bit);
+ long time4 = System.nanoTime();
+ comp += time2 - time1;
+ compwm += time3 - time2;
+ decomp += time4 - time3;
+ }
+ if (verbose)
+ System.out.println("bit = "
+ + bit
+ + " comp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (comp))
+ + " comp. speed wm = "
+ + dfspeed.format(N * times * 1000.0
+ / (compwm))
+ + " decomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (decomp)));
+ }
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void varyingLengthTest() {
+ testWithDeltasCore(true);
+ }
+
+ private void testWithDeltasCore(boolean verbose) {
+ DecimalFormat dfspeed = new DecimalFormat("0");
+ final int N = 32;
+ final int times = 100000;
+ Random r = new Random(0);
+ int[] data = new int[N];
+ int[] compressed = new int[N];
+ int[] icompressed = new int[N];
+ int[] uncompressed = new int[N];
+ for (int bit = 1; bit < 32; ++bit) {
+ long comp = 0;
+ long decomp = 0;
+ long icomp = 0;
+ long idecomp = 0;
+ for (int t = 0; t < times; ++t) {
+ data[0] = r.nextInt(1 << (bit == 31 ? 30 : bit));
+ for (int k = 1; k < N; ++k) {
+ data[k] = r.nextInt(1 << (bit == 31 ? 30 : bit))
+ + data[k - 1];
+ }
+ int[] tmpdata = Arrays
+ .copyOf(data, data.length);
+ long time1 = System.nanoTime();
+ Delta.delta(tmpdata);
+ BitPacking.fastpackwithoutmask(tmpdata, 0,
+ compressed, 0, bit);
+ long time2 = System.nanoTime();
+ BitPacking.fastunpack(compressed, 0,
+ uncompressed, 0, bit);
+ Delta.fastinverseDelta(uncompressed);
+ long time3 = System.nanoTime();
+ if (!Arrays.equals(data, uncompressed))
+ throw new RuntimeException("bug");
+ comp += time2 - time1;
+ decomp += time3 - time2;
+ tmpdata = Arrays.copyOf(data, data.length);
+ time1 = System.nanoTime();
+ if(bit == 26){
+ int tttt = 0;
+ }
+ IntegratedBitPacking.integratedpack(0, tmpdata,
+ 0, icompressed, 0, bit);
+ time2 = System.nanoTime();
+ IntegratedBitPacking.integratedunpack(0,
+ icompressed, 0, uncompressed, 0, bit);
+ time3 = System.nanoTime();
+ if (!Arrays.equals(icompressed, compressed))
+ throw new RuntimeException("ibug "
+ + bit);
+ if (!Arrays.equals(data, uncompressed))
+ throw new RuntimeException("bug " + bit);
+ icomp += time2 - time1;
+ idecomp += time3 - time2;
+ }
+ if (verbose)
+ System.out.println("bit = "
+ + bit
+ + " comp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (comp))
+ + " decomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (decomp))
+ + " icomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (icomp))
+ + " idecomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (idecomp)));
+ }
+ }
+}
diff --git a/src/test/java/me/lemire/integercompression/SkippableBasicTest.java b/src/test/java/me/lemire/integercompression/SkippableBasicTest.java
index d965992..d67a4e8 100644
--- a/src/test/java/me/lemire/integercompression/SkippableBasicTest.java
+++ b/src/test/java/me/lemire/integercompression/SkippableBasicTest.java
@@ -25,7 +25,8 @@ public class SkippableBasicTest {
new SkippableComposition(new FastPFOR128(), new VariableByte()),
new SkippableComposition(new FastPFOR(), new VariableByte()),
new Simple9(),
- new Simple16() };
+ new Simple16()
+ };
/**
diff --git a/src/test/java/me/lemire/integercompression/XorBinaryPackingTest.java b/src/test/java/me/lemire/integercompression/XorBinaryPackingTest.java
index 3201b02..72f7871 100644
--- a/src/test/java/me/lemire/integercompression/XorBinaryPackingTest.java
+++ b/src/test/java/me/lemire/integercompression/XorBinaryPackingTest.java
@@ -20,11 +20,6 @@
public final class XorBinaryPackingTest
{
-
-
-
-
-
private static void checkCompressAndUncompress(String label, int[] data) {
XorBinaryPacking codec = new XorBinaryPacking();
int[] compBuf = TestUtils.compress(codec, data);
diff --git a/src/test/java/me/lemire/integercompression/Xue_BenchmarkBitPackingTesting.java b/src/test/java/me/lemire/integercompression/Xue_BenchmarkBitPackingTesting.java
new file mode 100644
index 0000000..9c7b8b9
--- /dev/null
+++ b/src/test/java/me/lemire/integercompression/Xue_BenchmarkBitPackingTesting.java
@@ -0,0 +1,168 @@
+package me.lemire.integercompression; /**
+ * This code is released under the
+ * Apache License Version 2.0 http://www.apache.org/licenses/.
+ *
+ * (c) Daniel Lemire, http://lemire.me/en/
+ */
+//package me.lemire.integercompression.benchmarktools;
+import me.lemire.integercompression.benchmarktools.*;
+import me.lemire.integercompression.BitPacking;
+import me.lemire.integercompression.differential.Delta;
+import me.lemire.integercompression.differential.IntegratedBitPacking;
+
+import org.junit.Test;
+import java.text.DecimalFormat;
+import java.util.Arrays;
+import java.util.Random;
+
+/**
+ * Class used to benchmark the speed of bit packing. (For expert use.)
+ *
+ * @author Xue Li
+ *
+ */
+public class Xue_BenchmarkBitPackingTesting {
+ @Test
+ public void test(){
+ testCore(true);
+ testCore(false);
+ }
+ private void testCore(boolean verbose) {
+ DecimalFormat dfspeed = new DecimalFormat("0");
+ final int N = 32;
+ final int times = 100000;
+ Random r = new Random(0);
+ int[] data = new int[N];
+ int[] compressed = new int[N];
+ int[] uncompressed = new int[N];
+ for (int bit = 0; bit < 32; ++bit) {
+ long comp = 0;
+ long compwm = 0;
+ long decomp = 0;
+ for (int t = 0; t < times; ++t) {
+ for (int k = 0; k < N; ++k) {
+ data[k] = r.nextInt(1 << (bit == 31 ? 30 : bit));
+ }
+ long time1 = System.nanoTime();
+ BitPacking
+ .fastpack(data, 0, compressed, 0, bit);
+ long time2 = System.nanoTime();
+ BitPacking.fastpackwithoutmask(data, 0,
+ compressed, 0, bit);
+ long time3 = System.nanoTime();
+ BitPacking.fastunpack(compressed, 0,
+ uncompressed, 0, bit);
+ long time4 = System.nanoTime();
+ comp += time2 - time1;
+ compwm += time3 - time2;
+ decomp += time4 - time3;
+ }
+ if (verbose)
+ System.out.println("bit = "
+ + bit
+ + " comp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (comp))
+ + " comp. speed wm = "
+ + dfspeed.format(N * times * 1000.0
+ / (compwm))
+ + " decomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (decomp)));
+ }
+ }
+ @Test
+ public void testWithDeltas(){
+ testWithDeltasCore(false);
+ testWithDeltasCore(true);
+ }
+ private void testWithDeltasCore(boolean verbose) {
+ DecimalFormat dfspeed = new DecimalFormat("0");
+ final int N = 32;
+ final int times = 100000;
+ Random r = new Random(0);
+ int[] data = new int[N];
+ int[] compressed = new int[N];
+ int[] icompressed = new int[N];
+ int[] uncompressed = new int[N];
+ for (int bit = 1; bit < 32; ++bit) {
+ long comp = 0;
+ long decomp = 0;
+ long icomp = 0;
+ long idecomp = 0;
+ for (int t = 0; t < times; ++t) {
+ data[0] = r.nextInt(1 << (bit == 31 ? 30 : bit));
+ for (int k = 1; k < N; ++k) {
+ data[k] = r.nextInt(1 << (bit == 31 ? 30 : bit))
+ + data[k - 1];
+ }
+ int[] tmpdata = Arrays
+ .copyOf(data, data.length);
+ long time1 = System.nanoTime();
+ Delta.delta(tmpdata);
+ BitPacking.fastpackwithoutmask(tmpdata, 0,
+ compressed, 0, bit);
+ long time2 = System.nanoTime();
+ BitPacking.fastunpack(compressed, 0,
+ uncompressed, 0, bit);
+ Delta.fastinverseDelta(uncompressed);
+ long time3 = System.nanoTime();
+ if (!Arrays.equals(data, uncompressed))
+ throw new RuntimeException("bug");
+ comp += time2 - time1;
+ decomp += time3 - time2;
+ tmpdata = Arrays.copyOf(data, data.length);
+ time1 = System.nanoTime();
+ if(bit == 26){
+ int tttt = 0;
+ }
+ IntegratedBitPacking.integratedpack(0, tmpdata,
+ 0, icompressed, 0, bit);
+ time2 = System.nanoTime();
+ IntegratedBitPacking.integratedunpack(0,
+ icompressed, 0, uncompressed, 0, bit);
+ time3 = System.nanoTime();
+ if (!Arrays.equals(icompressed, compressed))
+ throw new RuntimeException("ibug "
+ + bit);
+ if (!Arrays.equals(data, uncompressed))
+ throw new RuntimeException("bug " + bit);
+ icomp += time2 - time1;
+ idecomp += time3 - time2;
+ }
+ if (verbose)
+ System.out.println("bit = "
+ + bit
+ + " comp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (comp))
+ + " decomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (decomp))
+ + " icomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (icomp))
+ + " idecomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (idecomp)));
+ }
+ }
+
+ /**
+ * Main method
+ *
+ * @param args
+ * command-line arguments
+ */
+ /*
+ public static void main(String[] args) {
+ System.out.println("Testing packing and delta ");
+ testWithDeltas(false);
+ testWithDeltas(true);
+ System.out.println("Testing packing alone ");
+ test(false);
+ test(true);
+ }
+ */
+
+}
diff --git a/src/test/java/me/lemire/integercompression/Xue_DeltaTest.java b/src/test/java/me/lemire/integercompression/Xue_DeltaTest.java
new file mode 100644
index 0000000..623ef67
--- /dev/null
+++ b/src/test/java/me/lemire/integercompression/Xue_DeltaTest.java
@@ -0,0 +1,95 @@
+package me.lemire.integercompression;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import me.lemire.integercompression.differential.Delta;
+
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Tests for class Delta.
+ *
+ * @author Xue Li
+ */
+@SuppressWarnings({ "static-method" })
+public class Xue_DeltaTest {
+
+ /**
+ *
+ */
+ @Test
+ public void simpleDeltaTest() {
+
+ int[] data = new int[1024];
+
+ for (int k = 0; k < 1024; ++k) data[k] = k;
+
+ Delta.delta(data);
+
+ for (int k = 1; k < 1024; ++k){
+ assertEquals("simple delta", data[k], 1);
+ }
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void deltaWithInitialTest() {
+ int[] data = new int[1024]; //0 1 2 3 4 5 6 7 8 9 10 ... => 0 1 2 -5 1 1 1 1 8 9 10, return 7
+
+ int start = 3, length = 5, init;
+ int[] out = new int[length];
+
+ for (int k = 0; k < 1024; ++k) data[k] = k;
+ init = data[start - 1];
+
+ Delta.delta(data, start, length, init, out);
+
+ for (int k = 0; k < length; ++k){
+ assertEquals("deltaWithInitialTest", out[k], 1);
+ }
+ }
+
+ @Test
+ public void inverseDeltaTest(){
+ int[] data = new int[1024];
+
+ for (int k = 0; k < 1024; ++k) data[k] = k;
+
+ Delta.delta(data);
+ Delta.inverseDelta(data);
+
+ for (int k = 0; k < 1024; ++k){
+ assertEquals("inverseDeltaTest", data[k], k);
+ }
+ }
+
+ @Test
+ public void fastinverseDeltaTest(){
+ int[] data = new int[1024];
+
+ for (int k = 0; k < 1024; ++k) data[k] = k;
+
+ Delta.delta(data);
+ Delta.fastinverseDelta(data);
+
+ for (int k = 0; k < 1024; ++k){
+ assertEquals("inverseDeltaTest", data[k], k);
+ }
+ }
+
+ @Test
+ public void fastinverseDeltaWithInitialTest(){
+ int[] data = {0, 1, 2, 1, 1, 1, 1, 1, 8, 9}; //0 1 2 3 4 5 6 7 8 9 10 ... => 0 1 2 -5 1 1 1 1 8 9 10, return 7
+ int start = 3, length = 5, init = 2;
+
+ Delta.fastinverseDelta(data, start, length, init);
+
+ for (int k = 0; k < length; ++k){
+ assertEquals("fastinverseDeltaWithInitialTest", data[k], k);
+ }
+ }
+}
diff --git a/src/test/java/me/lemire/integercompression/Xue_GroupSimpleTest.java b/src/test/java/me/lemire/integercompression/Xue_GroupSimpleTest.java
new file mode 100644
index 0000000..8f76e90
--- /dev/null
+++ b/src/test/java/me/lemire/integercompression/Xue_GroupSimpleTest.java
@@ -0,0 +1,162 @@
+package me.lemire.integercompression;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+
+
+/**
+ * Just some basic sanity tests.
+ *
+ * @author Daniel Lemire
+ */
+@SuppressWarnings({ "static-method" })
+public class Xue_GroupSimpleTest {
+ SkippableIntegerCODEC[] codecs = {
+ new GroupSimple9()
+ };
+
+
+ /**
+ *
+ */
+ @Test
+ public void consistentTest() {
+ int bitLength[] = { 1, 2, 3, 4, 5, 7, 9, 14, 28 };
+ int codeNum[] = { 28, 14, 9, 7, 5, 4, 3, 2, 1 };
+ for(int s1 = 0 ; s1 < 9; ++s1){
+ for(int s2 = 0; s2 < 9; ++s2){
+ int max1 = 1 << bitLength[s1];
+ int max2 = 1 << bitLength[s2];
+ int num1 = codeNum[s1];
+ int num2 = codeNum[s2];
+
+ int N = num1 + num2;
+ if(N < 57) N = 57;
+ int[] data = new int[N];
+
+ int i = 0;
+ for(; i < num1; ++i){
+ data[i] = max1 - 1;
+ }
+ for(; i < N; ++i){
+ data[i] = max2 - 1;
+ }
+
+ oneTest(N, data);
+
+ }
+ }
+
+
+ }
+ private void oneTest(int N, int[] data){
+ int[] rev = new int[N];
+
+ //for (int k = 0; k < N; ++k)
+ // data[k] = k % 128;
+ for (SkippableIntegerCODEC c : codecs) {
+ System.out.println("[SkippeableBasicTest.consistentTest] codec = "
+ + c);
+ int[] outBuf = new int[N + 1024];
+ for (int n = 0; n <= N; ++n) {
+ IntWrapper inPos = new IntWrapper();
+ IntWrapper outPos = new IntWrapper();
+ c.headlessCompress(data, inPos, n, outBuf, outPos);
+
+ IntWrapper inPoso = new IntWrapper();
+ IntWrapper outPoso = new IntWrapper();
+ c.headlessUncompress(outBuf, inPoso, outPos.get(), rev,
+ outPoso, n);
+ if (outPoso.get() != n) {
+ throw new RuntimeException("bug "+n);
+ }
+ if (inPoso.get() != outPos.get()) {
+ throw new RuntimeException("bug "+n+" "+inPoso.get()+" "+outPos.get());
+ }
+ for (int j = 0; j < n; ++j)
+ if (data[j] != rev[j]) {
+ throw new RuntimeException("bug");
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void varyingLengthTest() {
+ int N = 4096;
+ int[] data = new int[N];
+ for (int k = 0; k < N; ++k)
+ data[k] = k;
+ for (SkippableIntegerCODEC c : codecs) {
+ System.out.println("[SkippeableBasicTest.varyingLengthTest] codec = "+c);
+ for (int L = 1; L <= 128; L++) {
+ int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
+ int[] answer = TestUtils.uncompressHeadless(c, comp, L);
+ for (int k = 0; k < L; ++k)
+ if (answer[k] != data[k])
+ throw new RuntimeException("bug "+c.toString()+" "+k+" "+answer[k]+" "+data[k]);
+ }
+ for (int L = 128; L <= N; L *= 2) {
+ int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
+ int[] answer = TestUtils.uncompressHeadless(c, comp, L);
+ for (int k = 0; k < L; ++k)
+ if (answer[k] != data[k])
+ throw new RuntimeException("bug");
+ }
+
+ }
+ }
+
+ /**
+ *
+ */
+ /*
+ @Test
+
+ public void varyingLengthTest2() {
+ int N = 128;
+ int[] data = new int[N];
+ data[127] = -1;
+ for (SkippableIntegerCODEC c : codecs) {
+ System.out.println("[SkippeableBasicTest.varyingLengthTest2] codec = "+c);
+
+ try {
+ // CODEC Simple9 is limited to "small" integers.
+ if (c.getClass().equals(
+ Class.forName("me.lemire.integercompression.Simple9")))
+ continue;
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ try {
+ // CODEC Simple16 is limited to "small" integers.
+ if (c.getClass().equals(
+ Class.forName("me.lemire.integercompression.Simple16")))
+ continue;
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ for (int L = 1; L <= 128; L++) {
+ int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
+ int[] answer = TestUtils.uncompressHeadless(c, comp, L);
+ for (int k = 0; k < L; ++k)
+ if (answer[k] != data[k])
+ throw new RuntimeException("bug at k = "+k+" "+answer[k]+" "+data[k]+" for "+c.toString());
+ }
+ for (int L = 128; L <= N; L *= 2) {
+ int[] comp = TestUtils.compressHeadless(c, Arrays.copyOf(data, L));
+ int[] answer = TestUtils.uncompressHeadless(c, comp, L);
+ for (int k = 0; k < L; ++k)
+ if (answer[k] != data[k])
+ throw new RuntimeException("bug");
+ }
+
+ }
+ }
+
+ */
+}
diff --git a/src/test/java/me/lemire/integercompression/Xue_IntegratedBitPackingTest.java b/src/test/java/me/lemire/integercompression/Xue_IntegratedBitPackingTest.java
new file mode 100644
index 0000000..30a9a63
--- /dev/null
+++ b/src/test/java/me/lemire/integercompression/Xue_IntegratedBitPackingTest.java
@@ -0,0 +1,152 @@
+package me.lemire.integercompression;
+
+import me.lemire.integercompression.differential.Delta;
+import me.lemire.integercompression.differential.IntegratedBitPacking;
+import org.junit.Test;
+
+import java.text.DecimalFormat;
+import java.util.Arrays;
+import java.util.Random;
+
+
+/**
+ * Tests for class GroupSimple9.
+ *
+ * @author Xue Li
+ */
+@SuppressWarnings({ "static-method" })
+public class Xue_IntegratedBitPackingTest {
+
+
+ /**
+ *
+ */
+ @Test
+ public void Test() {
+ testCore(true);
+ }
+ private void testCore(boolean verbose) {
+ DecimalFormat dfspeed = new DecimalFormat("0");
+ final int N = 32;
+ final int times = 100000;
+ Random r = new Random(0);
+ int[] data = new int[N];
+ int[] compressed = new int[N];
+ int[] uncompressed = new int[N];
+ for (int bit = 0; bit < 32; ++bit) {
+ long comp = 0;
+ long compwm = 0;
+ long decomp = 0;
+ for (int t = 0; t < times; ++t) {
+ for (int k = 0; k < N; ++k) {
+ data[k] = r.nextInt(1 << (bit == 31 ? 30 : bit));
+ }
+ long time1 = System.nanoTime();
+ BitPacking
+ .fastpack(data, 0, compressed, 0, bit);
+ long time2 = System.nanoTime();
+ BitPacking.fastpackwithoutmask(data, 0,
+ compressed, 0, bit);
+ long time3 = System.nanoTime();
+ BitPacking.fastunpack(compressed, 0,
+ uncompressed, 0, bit);
+ long time4 = System.nanoTime();
+ comp += time2 - time1;
+ compwm += time3 - time2;
+ decomp += time4 - time3;
+ }
+ if (verbose)
+ System.out.println("bit = "
+ + bit
+ + " comp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (comp))
+ + " comp. speed wm = "
+ + dfspeed.format(N * times * 1000.0
+ / (compwm))
+ + " decomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (decomp)));
+ }
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void varyingLengthTest() {
+ testWithDeltasCore(true);
+ }
+
+ private void testWithDeltasCore(boolean verbose) {
+ DecimalFormat dfspeed = new DecimalFormat("0");
+ final int N = 32;
+ final int times = 100000;
+ Random r = new Random(0);
+ int[] data = new int[N];
+ int[] compressed = new int[N];
+ int[] icompressed = new int[N];
+ int[] uncompressed = new int[N];
+ for (int bit = 1; bit < 32; ++bit) {
+ long comp = 0;
+ long decomp = 0;
+ long icomp = 0;
+ long idecomp = 0;
+ for (int t = 0; t < times; ++t) {
+ data[0] = r.nextInt(1 << (bit == 31 ? 30 : bit));
+ for (int k = 1; k < N; ++k) {
+ data[k] = r.nextInt(1 << (bit == 31 ? 30 : bit))
+ + data[k - 1];
+ }
+ int[] tmpdata = Arrays
+ .copyOf(data, data.length);
+ long time1 = System.nanoTime();
+ Delta.delta(tmpdata);
+ BitPacking.fastpackwithoutmask(tmpdata, 0,
+ compressed, 0, bit);
+ long time2 = System.nanoTime();
+ BitPacking.fastunpack(compressed, 0,
+ uncompressed, 0, bit);
+ Delta.fastinverseDelta(uncompressed);
+ long time3 = System.nanoTime();
+ if (!Arrays.equals(data, uncompressed))
+ throw new RuntimeException("bug");
+ comp += time2 - time1;
+ decomp += time3 - time2;
+ tmpdata = Arrays.copyOf(data, data.length);
+ time1 = System.nanoTime();
+ if(bit == 26){
+ int tttt = 0;
+ }
+ IntegratedBitPacking.integratedpack(0, tmpdata,
+ 0, icompressed, 0, bit);
+ time2 = System.nanoTime();
+ IntegratedBitPacking.integratedunpack(0,
+ icompressed, 0, uncompressed, 0, bit);
+ time3 = System.nanoTime();
+ if (!Arrays.equals(icompressed, compressed))
+ throw new RuntimeException("ibug "
+ + bit);
+ if (!Arrays.equals(data, uncompressed))
+ throw new RuntimeException("bug " + bit);
+ icomp += time2 - time1;
+ idecomp += time3 - time2;
+ }
+ if (verbose)
+ System.out.println("bit = "
+ + bit
+ + " comp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (comp))
+ + " decomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (decomp))
+ + " icomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (icomp))
+ + " idecomp. speed = "
+ + dfspeed.format(N * times * 1000.0
+ / (idecomp)));
+ }
+ }
+}