public Slice serialize() { compact(); int requiredBytes = SizeOf.SIZE_OF_BYTE + // format SizeOf.SIZE_OF_INT + // max buckets SizeOf.SIZE_OF_INT + // entry count SizeOf.SIZE_OF_DOUBLE * nextIndex + // values SizeOf.SIZE_OF_DOUBLE * nextIndex; // weights return Slices.allocate(requiredBytes) .getOutput() .appendByte(FORMAT_TAG) .appendInt(maxBuckets) .appendInt(nextIndex) .appendBytes(Slices.wrappedDoubleArray(values, 0, nextIndex)) .appendBytes(Slices.wrappedDoubleArray(weights, 0, nextIndex)) .getUnderlyingSlice(); }
private static Block createChannel(int positionCount, int mapSize, Type valueType) { BlockBuilder blockBuilder = JSON.createBlockBuilder(null, positionCount); for (int position = 0; position < positionCount; position++) { SliceOutput jsonSlice = new DynamicSliceOutput(20 * mapSize); jsonSlice.appendByte('{'); for (int i = 0; i < mapSize; i++) { if (i != 0) { jsonSlice.appendByte(','); } String key = "key" + i; String value = generateRandomJsonValue(valueType); jsonSlice.appendByte('"'); jsonSlice.appendBytes(key.getBytes()); jsonSlice.appendBytes("\":".getBytes()); jsonSlice.appendBytes(value.getBytes()); } jsonSlice.appendByte('}'); JSON.writeSlice(blockBuilder, jsonSlice.slice()); } return blockBuilder.build(); }
@Override public void serialize(DigestAndPercentileArrayState state, BlockBuilder out) { if (state.getDigest() == null) { out.appendNull(); } else { Slice digest = state.getDigest().serialize(); SliceOutput output = Slices.allocate( SIZE_OF_INT + // number of percentiles state.getPercentiles().size() * SIZE_OF_DOUBLE + // percentiles SIZE_OF_INT + // digest length digest.length()) // digest .getOutput(); // write percentiles List<Double> percentiles = state.getPercentiles(); output.appendInt(percentiles.size()); for (double percentile : percentiles) { output.appendDouble(percentile); } output.appendInt(digest.length()); output.appendBytes(digest); VARBINARY.writeSlice(out, output.slice()); } }
public Slice serialize() { try (SliceOutput output = new DynamicSliceOutput(estimatedSerializedSize())) { output.appendByte(UNCOMPRESSED_FORMAT); Slice serializedHll = hll.serialize(); output.appendInt(serializedHll.length()); output.appendBytes(serializedHll); output.appendInt(maxHashes); output.appendInt(minhash.size()); for (long key : minhash.keySet()) { output.appendLong(key); } for (short value : minhash.values()) { output.appendShort(value); } return output.slice(); } catch (IOException e) { throw new UncheckedIOException(e); } }
@Override public void serialize(DigestAndPercentileState state, BlockBuilder out) { if (state.getDigest() == null) { out.appendNull(); } else { Slice serialized = state.getDigest().serialize(); SliceOutput output = Slices.allocate(SIZE_OF_DOUBLE + SIZE_OF_INT + serialized.length()).getOutput(); output.appendDouble(state.getPercentile()); output.appendInt(serialized.length()); output.appendBytes(serialized); VARBINARY.writeSlice(out, output.slice()); } }
private static Block createChannel(int positionCount, int mapSize, Type elementType) { BlockBuilder blockBuilder = JSON.createBlockBuilder(null, positionCount); for (int position = 0; position < positionCount; position++) { SliceOutput jsonSlice = new DynamicSliceOutput(20 * mapSize); jsonSlice.appendByte('['); for (int i = 0; i < mapSize; i++) { if (i != 0) { jsonSlice.appendByte(','); } String value = generateRandomJsonValue(elementType); jsonSlice.appendBytes(value.getBytes()); } jsonSlice.appendByte(']'); JSON.writeSlice(blockBuilder, jsonSlice.slice()); } return blockBuilder.build(); }
sliceOutput.appendBytes(sliceBetweenReplacements); appendReplacement(sliceOutput, source, pattern, matcher.getEagerRegion(), replacement); sliceOutput.appendBytes(source.slice(lastEnd, source.length() - lastEnd));
int end = region.end[backref]; if (beg != -1 && end != -1) { // the specific group doesn't exist in the current match, skip result.appendBytes(source.slice(beg, end - beg));
output.appendBytes(unmatched); output.appendBytes(replaced);
output.appendBytes(replaced);
public Slice serialize() { compact(); int requiredBytes = SizeOf.SIZE_OF_BYTE + // format SizeOf.SIZE_OF_INT + // max buckets SizeOf.SIZE_OF_INT + // entry count SizeOf.SIZE_OF_DOUBLE * nextIndex + // values SizeOf.SIZE_OF_DOUBLE * nextIndex; // weights return Slices.allocate(requiredBytes) .getOutput() .appendByte(FORMAT_TAG) .appendInt(maxBuckets) .appendInt(nextIndex) .appendBytes(Slices.wrappedDoubleArray(values, 0, nextIndex)) .appendBytes(Slices.wrappedDoubleArray(weights, 0, nextIndex)) .getUnderlyingSlice(); }
public Slice serialize() { compact(); int requiredBytes = SizeOf.SIZE_OF_BYTE + // format SizeOf.SIZE_OF_INT + // max buckets SizeOf.SIZE_OF_INT + // entry count SizeOf.SIZE_OF_DOUBLE * nextIndex + // values SizeOf.SIZE_OF_DOUBLE * nextIndex; // weights return Slices.allocate(requiredBytes) .getOutput() .appendByte(FORMAT_TAG) .appendInt(maxBuckets) .appendInt(nextIndex) .appendBytes(Slices.wrappedDoubleArray(values, 0, nextIndex)) .appendBytes(Slices.wrappedDoubleArray(weights, 0, nextIndex)) .getUnderlyingSlice(); }
public Slice serialize() { compact(); int requiredBytes = SizeOf.SIZE_OF_BYTE + // format SizeOf.SIZE_OF_INT + // max buckets SizeOf.SIZE_OF_INT + // entry count SizeOf.SIZE_OF_DOUBLE * nextIndex + // values SizeOf.SIZE_OF_DOUBLE * nextIndex; // weights return Slices.allocate(requiredBytes) .getOutput() .appendByte(FORMAT_TAG) .appendInt(maxBuckets) .appendInt(nextIndex) .appendBytes(Slices.wrappedDoubleArray(values, 0, nextIndex)) .appendBytes(Slices.wrappedDoubleArray(weights, 0, nextIndex)) .getUnderlyingSlice(); }
public static void combine(Type type, ArrayAggregationState state, ArrayAggregationState otherState) { SliceOutput s1 = state.getSliceOutput(); SliceOutput s2 = otherState.getSliceOutput(); if (s1 == null && s2 != null) { state.setSliceOutput(s2); state.setEntries(otherState.getEntries()); } else if (s1 != null) { s1.appendBytes(s2.slice()); state.setEntries(state.getEntries() + otherState.getEntries()); } }
private static void appendTo(Type type, SliceOutput output, Block block, int position) { if (type.getJavaType() == long.class) { output.appendLong(type.getLong(block, position)); } else if (type.getJavaType() == double.class) { output.appendDouble(type.getDouble(block, position)); } else if (type.getJavaType() == Slice.class) { Slice s = type.getSlice(block, position); output.appendInt(s.length()); output.appendBytes(s); } else if (type.getJavaType() == boolean.class) { output.appendByte(type.getBoolean(block, position) ? 1 : 0); } else { throw new IllegalArgumentException("Unsupported type: " + type.getJavaType().getSimpleName()); } }
@Override public void deserialize(Block block, int index, ArrayAggregationState state) { SliceInput input = block.getSlice(index, 0, block.getSliceLength(index)).getInput(); long entries = input.readLong(); state.setEntries(entries); if (entries > 0) { long length = input.readLong(); SliceOutput sliceOutput = new DynamicSliceOutput((int) length); sliceOutput.appendBytes(input.readSlice((int) length)); state.setSliceOutput(sliceOutput); } } }
@Override public void serialize(DigestAndPercentileState state, BlockBuilder out) { if (state.getDigest() == null) { out.appendNull(); } else { Slice serialized = state.getDigest().serialize(); SliceOutput output = Slices.allocate(SIZE_OF_DOUBLE + SIZE_OF_INT + serialized.length()).getOutput(); output.appendDouble(state.getPercentile()); output.appendInt(serialized.length()); output.appendBytes(serialized); VARBINARY.writeSlice(out, output.slice()); } }
@Override public void serialize(DigestAndPercentileState state, BlockBuilder out) { if (state.getDigest() == null) { out.appendNull(); } else { Slice serialized = state.getDigest().serialize(); SliceOutput output = Slices.allocate(SIZE_OF_DOUBLE + SIZE_OF_INT + serialized.length()).getOutput(); output.appendDouble(state.getPercentile()); output.appendInt(serialized.length()); output.appendBytes(serialized); VARBINARY.writeSlice(out, output.slice()); } }
private static Block createChannel(int positionCount, int mapSize, Type elementType) { BlockBuilder blockBuilder = JSON.createBlockBuilder(null, positionCount); for (int position = 0; position < positionCount; position++) { SliceOutput jsonSlice = new DynamicSliceOutput(20 * mapSize); jsonSlice.appendByte('['); for (int i = 0; i < mapSize; i++) { if (i != 0) { jsonSlice.appendByte(','); } String value = generateRandomJsonValue(elementType); jsonSlice.appendBytes(value.getBytes()); } jsonSlice.appendByte(']'); JSON.writeSlice(blockBuilder, jsonSlice.slice()); } return blockBuilder.build(); }
private static Block createChannel(int positionCount, int mapSize, Type elementType) { BlockBuilder blockBuilder = JSON.createBlockBuilder(null, positionCount); for (int position = 0; position < positionCount; position++) { SliceOutput jsonSlice = new DynamicSliceOutput(20 * mapSize); jsonSlice.appendByte('['); for (int i = 0; i < mapSize; i++) { if (i != 0) { jsonSlice.appendByte(','); } String value = generateRandomJsonValue(elementType); jsonSlice.appendBytes(value.getBytes()); } jsonSlice.appendByte(']'); JSON.writeSlice(blockBuilder, jsonSlice.slice()); } return blockBuilder.build(); }