use of org.janusgraph.diskstorage.WriteBuffer in project janusgraph by JanusGraph.
the class VariableLongTest method readWriteTest.
private void readWriteTest(final ReadWriteLong impl, long maxValue, long jump, boolean negative, boolean backward) {
Preconditions.checkArgument(maxValue % jump == 0);
long allocate = maxValue / jump * 8 * (negative ? 2 : 1);
Preconditions.checkArgument(allocate < (1 << 28));
WriteBuffer wb = new WriteByteBuffer((int) allocate);
int num = 0;
StopWatch w = new StopWatch();
w.start();
for (long i = (negative ? -maxValue : 0); i <= maxValue; i += jump) {
impl.write(wb, i);
num++;
}
// for (int i=0;i<b.remaining();i++) System.out.print(b.get(i)+"|");
w.stop();
ReadBuffer rb = wb.getStaticBuffer().asReadBuffer();
log.info("Writing " + num + " longs in " + rb.length() + " bytes. in time: " + w.getTime());
final ReadVerify read = (rb1, expected) -> {
int beforePos = rb1.getPosition();
long value = impl.read(rb1);
assertEquals(expected, value);
int length = Math.abs(rb1.getPosition() - beforePos);
assertEquals("On: " + expected, length, impl.length(expected));
};
if (backward) {
rb.movePositionTo(rb.length());
for (long i = maxValue; i != (negative ? -maxValue : 0); i -= jump) {
read.next(rb, i);
}
} else {
for (long i = (negative ? -maxValue : 0); i <= maxValue; i += jump) {
read.next(rb, i);
}
}
// Test boundaries
wb = new WriteByteBuffer(512);
impl.write(wb, 0);
impl.write(wb, Long.MAX_VALUE);
if (negative)
impl.write(wb, -Long.MAX_VALUE);
rb = wb.getStaticBuffer().asReadBuffer();
if (backward) {
rb.movePositionTo(rb.length());
if (negative)
assertEquals(-Long.MAX_VALUE, impl.read(rb));
assertEquals(Long.MAX_VALUE, impl.read(rb));
assertEquals(0, impl.read(rb));
} else {
assertEquals(0, impl.read(rb));
assertEquals(Long.MAX_VALUE, impl.read(rb));
if (negative)
assertEquals(-Long.MAX_VALUE, impl.read(rb));
}
}
use of org.janusgraph.diskstorage.WriteBuffer in project janusgraph by JanusGraph.
the class IDHandler method getRelationType.
public static StaticBuffer getRelationType(long relationTypeId, DirectionID dirID, boolean invisible) {
WriteBuffer b = new WriteByteBuffer(relationTypeLength(relationTypeId));
IDHandler.writeRelationType(b, relationTypeId, dirID, invisible);
return b.getStaticBuffer();
}
use of org.janusgraph.diskstorage.WriteBuffer in project janusgraph by JanusGraph.
the class ConsistentKeyLockerSerializer method toLockCol.
public StaticBuffer toLockCol(Instant ts, StaticBuffer rid, TimestampProvider provider) {
WriteBuffer b = new WriteByteBuffer(rid.length() + 8);
b.putLong(provider.getTime(ts));
WriteBufferUtil.put(b, rid);
return b.getStaticBuffer();
}
use of org.janusgraph.diskstorage.WriteBuffer in project janusgraph by JanusGraph.
the class VariableLong method positiveBuffer.
public static StaticBuffer positiveBuffer(final long value) {
WriteBuffer buffer = new WriteByteBuffer(positiveLength(value));
writePositive(buffer, value);
return buffer.getStaticBuffer();
}
use of org.janusgraph.diskstorage.WriteBuffer in project janusgraph by JanusGraph.
the class VariableLong method positiveBuffer.
public static StaticBuffer positiveBuffer(long[] value) {
int len = 0;
for (long aValue : value) len += positiveLength(aValue);
WriteBuffer buffer = new WriteByteBuffer(len);
for (long aValue : value) writePositive(buffer, aValue);
return buffer.getStaticBuffer();
}
Aggregations