Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public void headlessCompress(int[] in, IntWrapper inpos, int inlength, int[] out
public void headlessUncompress(int[] in, IntWrapper inpos, int inlength, int[] out,
IntWrapper outpos, int num) {
int init = inpos.get();
int outposInit = outpos.get();

F1.headlessUncompress(in, inpos, inlength, out, outpos, num);
if (inpos.get() == init) {
inpos.increment();
}
inlength -= inpos.get() - init;
num -= outpos.get();
num -= outpos.get() - outposInit;
F2.headlessUncompress(in, inpos, inlength, out, outpos, num);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ public void headlessUncompress(int[] in, IntWrapper inpos, int inlength,
if (inlength == 0)
return;
int init = inpos.get();
int outposInit = outpos.get();

F1.headlessUncompress(in, inpos, inlength, out, outpos,num,initvalue);
if (inpos.get() == init) {
inpos.increment();
}
inlength -= inpos.get() - init;

num -= outpos.get();
num -= outpos.get() - outposInit;
F2.headlessUncompress(in, inpos, inlength, out, outpos,num,initvalue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ public void headlessCompress(long[] in, IntWrapper inpos, int inlength, long[] o
public void headlessUncompress(long[] in, IntWrapper inpos, int inlength, long[] out,
IntWrapper outpos, int num) {
int init = inpos.get();
int outposInit = outpos.get();

F1.headlessUncompress(in, inpos, inlength, out, outpos, num);
if (inpos.get() == init) {
inpos.increment();
}
inlength -= inpos.get() - init;
num -= outpos.get();
num -= outpos.get() - outposInit;
F2.headlessUncompress(in, inpos, inlength, out, outpos, num);
}

Expand Down
49 changes: 49 additions & 0 deletions src/test/java/me/lemire/integercompression/SkippableBasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import me.lemire.integercompression.differential.SkippableIntegratedIntegerCODEC;
import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -236,4 +237,52 @@ private static void testMaxHeadlessCompressedLength(SkippableIntegerCODEC codec,
}
}
}

@Test
public void testUncompressOutputOffset_SkippableComposition() {
for (int offset : new int[] {0, 1, 6}) {
SkippableComposition codec = new SkippableComposition(new BinaryPacking(), new VariableByte());

int[] input = { 2, 3, 4, 5 };
int[] compressed = new int[codec.maxHeadlessCompressedLength(new IntWrapper(0), input.length)];
int[] uncompressed = new int[offset + input.length];

IntWrapper inputOffset = new IntWrapper(0);
IntWrapper compressedOffset = new IntWrapper(0);

codec.headlessCompress(input, inputOffset, input.length, compressed, compressedOffset);

int compressedLength = compressedOffset.get();
IntWrapper uncompressedOffset = new IntWrapper(offset);
compressedOffset = new IntWrapper(0);
codec.headlessUncompress(compressed, compressedOffset, compressedLength, uncompressed, uncompressedOffset, input.length);

assertArrayEquals(input, Arrays.copyOfRange(uncompressed, offset, offset + input.length));
}
}

@Test
public void testUncompressOutputOffset_SkippableIntegratedComposition() {
for (int offset : new int[] {0, 1, 6}) {
SkippableIntegratedComposition codec = new SkippableIntegratedComposition(new IntegratedBinaryPacking(), new IntegratedVariableByte());

int[] input = { 2, 3, 4, 5 };
int[] compressed = new int[codec.maxHeadlessCompressedLength(new IntWrapper(0), input.length)];
int[] uncompressed = new int[offset + input.length];

IntWrapper inputOffset = new IntWrapper(0);
IntWrapper compressedOffset = new IntWrapper(0);
IntWrapper initValue = new IntWrapper(0);

codec.headlessCompress(input, inputOffset, input.length, compressed, compressedOffset, initValue);

int compressedLength = compressedOffset.get();
IntWrapper uncompressedOffset = new IntWrapper(offset);
compressedOffset = new IntWrapper(0);
initValue = new IntWrapper(0);
codec.headlessUncompress(compressed, compressedOffset, compressedLength, uncompressed, uncompressedOffset, input.length, initValue);

assertArrayEquals(input, Arrays.copyOfRange(uncompressed, offset, offset + input.length));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import me.lemire.integercompression.TestUtils;
import me.lemire.integercompression.VariableByte;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -167,4 +168,27 @@ private static void testMaxHeadlessCompressedLength(SkippableLongCODEC codec, in
assertTrue(maxOutputLength <= outPos.get() + 1); // +1 because SkippableLongComposition always adds one extra integer for the potential header
}
}

@Test
public void testUncompressOutputOffset_SkippableLongComposition() {
for (int offset : new int[] {0, 1, 6}) {
SkippableLongComposition codec = new SkippableLongComposition(new LongBinaryPacking(), new LongVariableByte());

long[] input = { 2, 3, 4, 5 };
long[] compressed = new long[codec.maxHeadlessCompressedLength(new IntWrapper(0), input.length)];
long[] uncompressed = new long[offset + input.length];

IntWrapper inputOffset = new IntWrapper(0);
IntWrapper compressedOffset = new IntWrapper(0);

codec.headlessCompress(input, inputOffset, input.length, compressed, compressedOffset);

int compressedLength = compressedOffset.get();
IntWrapper uncompressedOffset = new IntWrapper(offset);
compressedOffset = new IntWrapper(0);
codec.headlessUncompress(compressed, compressedOffset, compressedLength, uncompressed, uncompressedOffset, input.length);

assertArrayEquals(input, Arrays.copyOfRange(uncompressed, offset, offset + input.length));
}
}
}