@Theory public void shouldRoundTripUtf8StringWithoutLength(final MutableDirectBuffer buffer) { final String value = "Hello£ World £"; final int encodedLength = buffer.putStringWithoutLengthUtf8(INDEX, value); assertThat(buffer.getStringWithoutLengthUtf8(INDEX, encodedLength), is(value)); } }
private void testAlignedWriteMethods(final MutableDirectBuffer buffer, final int offset) { buffer.putLong(offset + SIZE_OF_LONG, Long.MAX_VALUE); buffer.putLong(offset + SIZE_OF_LONG, Long.MAX_VALUE, BIG_ENDIAN); buffer.putDouble(offset + SIZE_OF_DOUBLE, Double.MAX_VALUE); buffer.putDouble(offset + SIZE_OF_DOUBLE, Double.MAX_VALUE, BIG_ENDIAN); buffer.putInt(offset + SIZE_OF_INT, Integer.MAX_VALUE); buffer.putInt(offset + SIZE_OF_INT, Integer.MAX_VALUE, BIG_ENDIAN); buffer.putFloat(offset + SIZE_OF_FLOAT, Float.MAX_VALUE); buffer.putFloat(offset + SIZE_OF_FLOAT, Float.MAX_VALUE, BIG_ENDIAN); buffer.putShort(offset + SIZE_OF_SHORT, Short.MAX_VALUE); buffer.putShort(offset + SIZE_OF_SHORT, Short.MAX_VALUE, BIG_ENDIAN); buffer.putChar(offset + SIZE_OF_CHAR, Character.MAX_VALUE); buffer.putChar(offset + SIZE_OF_CHAR, Character.MAX_VALUE, BIG_ENDIAN); buffer.putByte(offset + SIZE_OF_BYTE, Byte.MAX_VALUE); buffer.putByte(offset + SIZE_OF_BYTE, Byte.MAX_VALUE); buffer.putStringUtf8(offset + SIZE_OF_INT, TEST_STRING); buffer.putStringUtf8(offset + SIZE_OF_INT, TEST_STRING, BIG_ENDIAN); buffer.putStringUtf8(offset + SIZE_OF_INT, TEST_STRING, Integer.MAX_VALUE); buffer.putStringUtf8(offset + SIZE_OF_INT, TEST_STRING, BIG_ENDIAN, Integer.MAX_VALUE); buffer.putStringAscii(offset + SIZE_OF_INT, TEST_STRING); buffer.putStringAscii(offset + SIZE_OF_INT, TEST_STRING, BIG_ENDIAN); // string size is not read for these method => no need for 4-bytes // alignment buffer.putStringWithoutLengthUtf8(offset + SIZE_OF_BYTE, TEST_STRING); buffer.putStringWithoutLengthAscii(offset + SIZE_OF_BYTE, TEST_STRING); }
@Benchmark public void readKey(final Reader r, final Blackhole bh) { for (final int key : r.keys) { if (r.intKey) { r.wkb.putInt(0, key); } else { r.wkb.putStringWithoutLengthUtf8(0, r.padKey(key)); } bh.consume(r.map.get(copyOf(r.wkb.byteArray(), r.keySize))); } }
@Benchmark public void readKey(final Reader r, final Blackhole bh) throws IOException { for (final int key : r.keys) { if (r.intKey) { r.wkb.putInt(0, key); } else { r.wkb.putStringWithoutLengthUtf8(0, r.padKey(key)); } bh.consume(r.db.get(r.wkb.byteArray())); } }
@Benchmark public void readKey(final Reader r, final Blackhole bh) { for (final int key : r.keys) { if (r.intKey) { r.wkb.putInt(0, key); } else { r.wkb.putStringWithoutLengthUtf8(0, r.padKey(key)); } bh.consume(r.map.get(r.wkb.byteArray())); } }
void write() { final int rndByteMax = RND_MB.length - valSize; int rndByteOffset = 0; for (final int key : keys) { if (intKey) { wkb.putInt(0, key, LITTLE_ENDIAN); } else { wkb.putStringWithoutLengthUtf8(0, padKey(key)); } if (valRandom) { wvb.putBytes(0, RND_MB, rndByteOffset, valSize); rndByteOffset += valSize; if (rndByteOffset >= rndByteMax) { rndByteOffset = 0; } } else { wvb.putInt(0, key); } // MvStore requires this copy, otherwise it never stores > 1 entry map.put(copyOf(wkb.byteArray(), keySize), copyOf(wvb.byteArray(), valSize)); } s.commit(); } }
@Benchmark public void readKey(final Reader r, final Blackhole bh) { for (final int key : r.keys) { if (r.intKey) { r.wkb.putInt(0, key); } else { r.wkb.putStringWithoutLengthUtf8(0, r.padKey(key)); } bh.consume(r.map.getUsing(r.wkb.byteArray(), r.wvb.byteArray())); } }
@Benchmark public void readKey(final Reader r, final Blackhole bh) { for (final int key : r.keys) { if (r.intKey) { r.rwKey.putInt(0, key); } else { r.rwKey.putStringWithoutLengthUtf8(0, r.padKey(key)); } bh.consume(r.c.get(r.rwKey, MDB_SET_KEY)); bh.consume(r.txn.val()); } }
@Benchmark public void readKey(final Reader r, final Blackhole bh) throws RocksDBException { for (final int key : r.keys) { if (r.intKey) { r.wkb.putInt(0, key); } else { r.wkb.putStringWithoutLengthUtf8(0, r.padKey(key)); } bh.consume(r.db.get(r.wkb.byteArray(), r.wvb.byteArray())); } }
void write() { final int rndByteMax = RND_MB.length - valSize; int rndByteOffset = 0; for (final int key : keys) { if (intKey) { wkb.putInt(0, key, LITTLE_ENDIAN); } else { wkb.putStringWithoutLengthUtf8(0, padKey(key)); } if (valRandom) { wvb.putBytes(0, RND_MB, rndByteOffset, valSize); rndByteOffset += valSize; if (rndByteOffset >= rndByteMax) { rndByteOffset = 0; } } else { wvb.putInt(0, key); } map.put(wkb.byteArray(), wvb.byteArray()); } } }
void write() { final int rndByteMax = RND_MB.length - valSize; int rndByteOffset = 0; for (final int key : keys) { if (intKey) { wkb.putInt(0, key, LITTLE_ENDIAN); } else { wkb.putStringWithoutLengthUtf8(0, padKey(key)); } if (valRandom) { wvb.putBytes(0, RND_MB, rndByteOffset, valSize); rndByteOffset += valSize; if (rndByteOffset >= rndByteMax) { rndByteOffset = 0; } } else { wvb.putInt(0, key); } map.put(wkb.byteArray(), wvb.byteArray()); } } }
wkb.putInt(0, key, LITTLE_ENDIAN); } else { wkb.putStringWithoutLengthUtf8(0, padKey(key));
@SuppressWarnings("PMD.NullAssignment") void write() { try (Txn<DirectBuffer> tx = env.txnWrite()) { try (Cursor<DirectBuffer> c = db.openCursor(tx);) { final PutFlags flags = sequential ? MDB_APPEND : null; final int rndByteMax = RND_MB.length - valSize; int rndByteOffset = 0; for (final int key : keys) { if (intKey) { rwKey.putInt(0, key); } else { rwKey.putStringWithoutLengthUtf8(0, padKey(key)); } if (valRandom) { rwVal.putBytes(0, RND_MB, rndByteOffset, valSize); rndByteOffset += valSize; if (rndByteOffset >= rndByteMax) { rndByteOffset = 0; } } else { rwVal.putInt(0, key); } c.put(rwKey, rwVal, flags); } } tx.commit(); } }
wkb.putInt(0, key, LITTLE_ENDIAN); } else { wkb.putStringWithoutLengthUtf8(0, padKey(key));