private void entryAdded(boolean isNull) { checkCapacity(); valueIsNull.appendByte(isNull ? 1 : 0); positionCount++; if (blockBuilderStatus != null) { blockBuilderStatus.addBytes(Byte.BYTES + fixedSize); } }
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 Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); SliceOutput newSlice = Slices.allocate(length * fixedSize).getOutput(); SliceOutput newValueIsNull = null; if (hasNullValue) { newValueIsNull = Slices.allocate(length).getOutput(); } for (int i = offset; i < offset + length; ++i) { int position = positions[i]; checkValidPosition(position, positionCount); if (hasNullValue) { newValueIsNull.appendByte(valueIsNull.getUnderlyingSlice().getByte(position)); } newSlice.writeBytes(getRawSlice(), position * fixedSize, fixedSize); } return new FixedWidthBlock(fixedSize, length, newSlice.slice(), newValueIsNull == null ? null : newValueIsNull.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(); }
@Override public void loadValue(SliceOutput output, int valueIndex) { output.appendByte((byte) valueIndex); }
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 loadValue(SliceOutput output, int valueIndex) { output.appendByte((byte) valueIndex); }
result.appendByte(nextByte); idx++;
@Override public void loadValue(SliceOutput output, int valueIndex) { output.appendByte((byte) valueIndex); }
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(); }
@Override public void loadValue(SliceOutput output, int valueIndex) { output.appendByte((byte) valueIndex); }
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 void entryAdded(boolean isNull) { checkCapacity(); valueIsNull.appendByte(isNull ? 1 : 0); positionCount++; if (blockBuilderStatus != null) { blockBuilderStatus.addBytes(Byte.BYTES + fixedSize); } }
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 void entryAdded(boolean isNull) { checkCapacity(); valueIsNull.appendByte(isNull ? 1 : 0); positionCount++; if (blockBuilderStatus != null) { blockBuilderStatus.addBytes(Byte.BYTES + fixedSize); } }
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(); }
@Test public void testEmpty() throws Exception { SliceOutput expected = new DynamicSliceOutput(1) .appendByte(3) // format tag .appendByte(12) // p .appendByte(0); // baseline for (int i = 0; i < 1 << (12 - 1); i++) { expected.appendByte(0); } // overflows expected.appendByte(0) .appendByte(0); assertSlicesEqual(makeHll(12).serialize(), expected.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(); }
@Test public void testEmpty() throws Exception { SliceOutput expected = new DynamicSliceOutput(1) .appendByte(3) // format tag .appendByte(12) // p .appendByte(0); // baseline for (int i = 0; i < 1 << (12 - 1); i++) { expected.appendByte(0); } // overflows expected.appendByte(0) .appendByte(0); assertSlicesEqual(makeHll(12).serialize(), expected.slice()); }