Skip to content
Open
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 @@ -22,8 +22,9 @@

import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.junit.Assume;
import org.junit.Test;
import org.slf4j.Logger;
Expand All @@ -41,30 +42,31 @@ public void unpackValuesUsingVector() {
}

private void unpackValuesUsingVectorBitWidth(int bitWidth) {
List<int[]> intInputs = getRangeData(bitWidth);

for (int[] intInput : intInputs) {
int pack8Count = intInput.length / 8;
int byteOutputSize = pack8Count * bitWidth;
byte[] byteOutput = new byte[byteOutputSize];
int[] output1 = new int[intInput.length];
int[] output2 = new int[intInput.length];
int[] output3 = new int[intInput.length];

BytePacker bytePacker = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
for (int i = 0; i < pack8Count; i++) {
bytePacker.pack8Values(intInput, 8 * i, byteOutput, bitWidth * i);
}
try (Stream<int[]> intInputs = getRangeData(bitWidth)) {
intInputs.forEach(intInput -> {
int pack8Count = intInput.length / 8;
int byteOutputSize = pack8Count * bitWidth;
byte[] byteOutput = new byte[byteOutputSize];
int[] output = new int[intInput.length];

BytePacker bytePacker = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
for (int i = 0; i < pack8Count; i++) {
bytePacker.pack8Values(intInput, 8 * i, byteOutput, bitWidth * i);
}

unpack8Values(bitWidth, byteOutput, output1);
unpackValuesUsingVectorArray(bitWidth, byteOutput, output2);
unpack8Values(bitWidth, byteOutput, output);
assertArrayEquals(intInput, output);
Arrays.fill(output, 0);

ByteBuffer byteBuffer = ByteBuffer.wrap(byteOutput);
unpackValuesUsingVectorByteBuffer(bitWidth, byteBuffer, output3);
unpackValuesUsingVectorArray(bitWidth, byteOutput, output);
assertArrayEquals(intInput, output);
Arrays.fill(output, 0);

assertArrayEquals(intInput, output1);
assertArrayEquals(intInput, output2);
assertArrayEquals(intInput, output3);
ByteBuffer byteBuffer = ByteBuffer.wrap(byteOutput);
unpackValuesUsingVectorByteBuffer(bitWidth, byteBuffer, output);
assertArrayEquals(intInput, output);
Arrays.fill(output, 0);
});
}
}

Expand Down Expand Up @@ -119,8 +121,7 @@ public void unpackValuesUsingVectorByteBuffer(int bitWidth, ByteBuffer input, in
}
}

private List<int[]> getRangeData(int bitWidth) {
List<int[]> result = new ArrayList<>();
private Stream<int[]> getRangeData(int bitWidth) {
int itemMax = 268435456;

long maxValue = getMaxValue(bitWidth);
Expand All @@ -131,9 +132,11 @@ private List<int[]> getRangeData(int bitWidth) {
++itemCount;
}

for (int i = 0; i < itemCount; i++) {
final int finalItemCount = itemCount;

return IntStream.range(0, finalItemCount).mapToObj(i -> {
int len;
if ((i == itemCount - 1) && mode != 0) {
if ((i == finalItemCount - 1) && mode != 0) {
len = mode;
} else {
len = itemMax;
Expand Down Expand Up @@ -162,9 +165,8 @@ private List<int[]> getRangeData(int bitWidth) {
array[j] = value;
j++;
}
result.add(array);
}
return result;
return array;
});
}

private long getMaxValue(int bitWidth) {
Expand Down
Loading