use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class FixedWidthBlockBuilder method copyPositions.
@Override
public Block copyPositions(List<Integer> positions) {
checkValidPositions(positions, positionCount);
SliceOutput newSlice = Slices.allocate(positions.size() * fixedSize).getOutput();
SliceOutput newValueIsNull = Slices.allocate(positions.size()).getOutput();
for (int position : positions) {
newValueIsNull.appendByte(valueIsNull.getUnderlyingSlice().getByte(position));
newSlice.appendBytes(getRawSlice().getBytes(position * fixedSize, fixedSize));
}
return new FixedWidthBlock(fixedSize, positions.size(), newSlice.slice(), newValueIsNull.slice());
}
use of io.airlift.slice.SliceOutput in project airlift by airlift.
the class TDigest method serializeInternal.
private Slice serializeInternal() {
Slice result = Slices.allocate(serializedSizeInBytes());
SliceOutput output = result.getOutput();
output.writeByte(TDigest.FORMAT_TAG);
output.writeDouble(min);
output.writeDouble(max);
output.writeDouble(compression);
output.writeDouble(totalWeight);
output.writeInt(centroidCount);
for (int i = 0; i < centroidCount; i++) {
output.writeDouble(means[i]);
}
for (int i = 0; i < centroidCount; i++) {
output.writeDouble(weights[i]);
}
checkState(!output.isWritable(), "Expected serialized size doesn't match actual written size");
return result;
}
use of io.airlift.slice.SliceOutput in project airlift by airlift.
the class QuantileDigest method serialize.
public Slice serialize() {
compress();
SliceOutput output = new DynamicSliceOutput(estimatedSerializedSizeInBytes());
output.writeByte(Flags.FORMAT);
output.writeDouble(maxError);
output.writeDouble(alpha);
output.writeLong(landmarkInSeconds);
output.writeLong(min);
output.writeLong(max);
output.writeInt(getNodeCount());
int[] nodes = new int[getNodeCount()];
postOrderTraversal(root, new Callback() {
int index;
@Override
public boolean process(int node) {
nodes[index++] = node;
return true;
}
});
for (int node : nodes) {
// The max value for a level is 64. Non-leaf nodes are decremented by 1
// to save a bit (so max serialized value is 63 (111111, 6 bits needed)).
// This is shifted 2 bits to give space for left/right child flags.
byte nodeStructure = (byte) (Math.max(levels[node] - 1, 0) << 2);
if (lefts[node] != -1) {
nodeStructure |= Flags.HAS_LEFT;
}
if (rights[node] != -1) {
nodeStructure |= Flags.HAS_RIGHT;
}
output.writeByte(nodeStructure);
output.writeDouble(counts[node]);
output.writeLong(values[node]);
}
return output.slice();
}
use of io.airlift.slice.SliceOutput in project airlift by airlift.
the class TestDenseSerialization method testEmpty.
@Test
public void testEmpty() throws Exception {
SliceOutput expected = new DynamicSliceOutput(1).appendByte(// format tag
3).appendByte(// p
12).appendByte(// baseline
0);
for (int i = 0; i < 1 << (12 - 1); i++) {
expected.appendByte(0);
}
// overflows
expected.appendByte(0).appendByte(0);
assertSlicesEqual(makeHll(12).serialize(), expected.slice());
}
use of io.airlift.slice.SliceOutput in project presto by prestodb.
the class PrecisionRecallStateSerializer method serialize.
@Override
public void serialize(PrecisionRecallState state, BlockBuilder out) {
// has histograms;
int requiredBytes = SizeOf.SIZE_OF_BYTE;
if (state.getTrueWeights() != null) {
requiredBytes += state.getTrueWeights().getRequiredBytesForSerialization();
requiredBytes += state.getFalseWeights().getRequiredBytesForSerialization();
}
SliceOutput sliceOut = Slices.allocate(requiredBytes).getOutput();
sliceOut.appendByte(state.getTrueWeights() == null ? 0 : 1);
if (state.getTrueWeights() != null) {
state.getTrueWeights().serialize(sliceOut);
state.getFalseWeights().serialize(sliceOut);
}
VARBINARY.writeSlice(out, sliceOut.getUnderlyingSlice());
}
Aggregations