Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/main/java/me/lemire/longcompression/LongAs2IntsCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public void uncompress(long[] in, IntWrapper inpos, int inlength, long[] out, In
highPart = !highPart;
}

// TODO What would be a relevant buffer size?
int[] buffer = new int[inlength * 16];
// A packed block can expand beyond a fixed multiple of its compressed size.
int[] buffer = new int[out.length - outpos.get()];

IntWrapper highPartsOutPosition = new IntWrapper();
highPartsCodec.uncompress(compressedHighParts,
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/me/lemire/longcompression/TestLongAs2IntsCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

package me.lemire.longcompression;

import java.util.Arrays;

import me.lemire.integercompression.BinaryPacking;
import me.lemire.integercompression.Composition;
import me.lemire.integercompression.IntWrapper;
import me.lemire.integercompression.IntegerCODEC;
import me.lemire.integercompression.VariableByte;

import org.junit.Assert;
import org.junit.Test;

Expand All @@ -28,4 +36,26 @@ public void testCodec_intermediateHighPowerOfTwo() {
Assert.assertEquals(3, LongTestUtils.compress((LongCODEC) codec, new long[] { 1L << 42 }).length);
}

@Test
public void testHighlyCompressedRoundTrip() {
IntegerCODEC packing = new Composition(new BinaryPacking(), new VariableByte());
LongCODEC packedCodec = new LongAs2IntsCodec(packing, packing);
long[] original = new long[1024];
long[] compressed = new long[original.length];
IntWrapper compressedEnd = new IntWrapper(2);
packedCodec.compress(original, new IntWrapper(), original.length, compressed, compressedEnd);

long[] decoded = new long[original.length + 2];
Arrays.fill(decoded, -1);
IntWrapper compressedStart = new IntWrapper(2);
IntWrapper decodedEnd = new IntWrapper(2);
packedCodec.uncompress(compressed, compressedStart, compressedEnd.get() - 2, decoded, decodedEnd);

Assert.assertEquals(compressedEnd.get(), compressedStart.get());
Assert.assertEquals(decoded.length, decodedEnd.get());
Assert.assertEquals(-1, decoded[0]);
Assert.assertEquals(-1, decoded[1]);
Assert.assertArrayEquals(original, Arrays.copyOfRange(decoded, 2, decoded.length));
}

}