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
4 changes: 2 additions & 2 deletions src/main/java/me/lemire/longcompression/LongVariableByte.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void headlessCompress(long[] in, IntWrapper inpos, int inlength, long[] o
buf.put((byte) extract7bits(5, val));
buf.put((byte) extract7bits(6, val));
buf.put((byte) (extract7bitsmaskless(7, (val)) | (1 << 7)));
} else if (val >= 0 && val < (1L << 63)) {
} else if (val >= 0) {
buf.put((byte) extract7bits(0, val));
buf.put((byte) extract7bits(1, val));
buf.put((byte) extract7bits(2, val));
Expand Down Expand Up @@ -175,7 +175,7 @@ public void compress(long[] in, IntWrapper inpos, int inlength, byte[] out,
out[outpostmp++] = (byte) extract7bits(5, val);
out[outpostmp++] = (byte) extract7bits(6, val);
out[outpostmp++] = (byte) (extract7bitsmaskless(7, (val)) | (1 << 7));
} else if (val >= 0 && val < (1L << 63)) {
} else if (val >= 0) {
out[outpostmp++] = (byte) extract7bits(0, val);
out[outpostmp++] = (byte) extract7bits(1, val);
out[outpostmp++] = (byte) extract7bits(2, val);
Expand Down
18 changes: 12 additions & 6 deletions src/test/java/me/lemire/longcompression/TestLongVariableByte.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ public LongCODEC getCodec() {
}

@Test
public void testCodec_intermediateHighPowerOfTwo() {
Assert.assertEquals(1, LongTestUtils.compress((LongCODEC) codec, new long[] { 1L << 42 }).length);
Assert.assertEquals(7, LongTestUtils.compress((ByteLongCODEC) codec, new long[] { 1L << 42 }).length);
Assert.assertEquals(1,
LongTestUtils.compressHeadless((SkippableLongCODEC) codec, new long[] { 1L << 42 }).length);
}
public void testCodec_allBitWidths() {
for (int bitWidth = 0; bitWidth <= 64; bitWidth++) {
long value = bitWidth == 0 ? 0 : 1L << (bitWidth - 1);

int expectedSizeInBytes = Math.max(1, (bitWidth + 6) / 7);
int expectedSizeInLongs = (expectedSizeInBytes > 8) ? 2 : 1;

Assert.assertEquals(expectedSizeInLongs, LongTestUtils.compress((LongCODEC) codec, new long[] { value }).length);
Assert.assertEquals(expectedSizeInBytes, LongTestUtils.compress((ByteLongCODEC) codec, new long[] { value }).length);
Assert.assertEquals(expectedSizeInLongs,
LongTestUtils.compressHeadless((SkippableLongCODEC) codec, new long[] { value }).length);
}
}
}