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
2 changes: 1 addition & 1 deletion src/main/java/org/xerial/snappy/BitShuffle.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static int unshuffle(ByteBuffer shuffled, BitShuffleType type, ByteBuffer
if (output.remaining() < uLen) {
throw new IllegalArgumentException("not enough space for output");
}
int numProcessed = impl.unshuffleDirectBuffer(shuffled, uPos, typeSize, uLen, output, shuffled.position());
int numProcessed = impl.unshuffleDirectBuffer(shuffled, uPos, typeSize, uLen, output, output.position());
assert(numProcessed == uLen);

// pos limit
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/org/xerial/snappy/BitShuffleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,31 @@ public void shuffleDirectDoubleArray()
assertEquals(Integer.MIN_VALUE, result.getDouble(), 0.0000001);
}

@Test
public void unshuffleWritesAtOutputPosition()
throws Exception
{
ByteBuffer testData = ByteBuffer.allocateDirect(32);
for (int i = 0; i < 8; i++) {
testData.putInt(i * 1000 + 7);
}
testData.flip();
ByteBuffer shuffled = ByteBuffer.allocateDirect(64);
shuffled.position(32);
BitShuffle.shuffle(testData, BitShuffleType.INT, shuffled);
assertEquals(32, shuffled.position());

ByteBuffer result = ByteBuffer.allocateDirect(64);
BitShuffle.unshuffle(shuffled, BitShuffleType.INT, result);
assertEquals(0, result.position());
for (int i = 0; i < 8; i++) {
assertEquals(i * 1000 + 7, result.getInt());
}
for (int i = 32; i < 64; i++) {
assertEquals(0, result.get(i));
}
}

@Test
public void shuffleLongArray()
throws Exception
Expand Down
Loading