Update Example.java, DatabaseMapDictionary.java, and 5 more files...
This commit is contained in:
parent
554facde13
commit
2bd69f0331
@ -7,7 +7,7 @@ import it.cavallium.dbengine.database.Column;
|
|||||||
import it.cavallium.dbengine.database.LLKeyValueDatabase;
|
import it.cavallium.dbengine.database.LLKeyValueDatabase;
|
||||||
import it.cavallium.dbengine.database.collections.DatabaseMapDictionary;
|
import it.cavallium.dbengine.database.collections.DatabaseMapDictionary;
|
||||||
import it.cavallium.dbengine.database.collections.DatabaseMapDictionaryDeep;
|
import it.cavallium.dbengine.database.collections.DatabaseMapDictionaryDeep;
|
||||||
import it.cavallium.dbengine.database.collections.FixedLengthSerializer;
|
import it.cavallium.dbengine.database.collections.SerializerFixedBinaryLength;
|
||||||
import it.cavallium.dbengine.database.collections.Serializer;
|
import it.cavallium.dbengine.database.collections.Serializer;
|
||||||
import it.cavallium.dbengine.database.collections.SubStageGetterSingleBytes;
|
import it.cavallium.dbengine.database.collections.SubStageGetterSingleBytes;
|
||||||
import it.cavallium.dbengine.database.disk.LLLocalDatabaseConnection;
|
import it.cavallium.dbengine.database.disk.LLLocalDatabaseConnection;
|
||||||
@ -62,7 +62,7 @@ public class Example {
|
|||||||
|
|
||||||
private static Mono<Void> testAtPut() {
|
private static Mono<Void> testAtPut() {
|
||||||
var ssg = new SubStageGetterSingleBytes();
|
var ssg = new SubStageGetterSingleBytes();
|
||||||
var ser = FixedLengthSerializer.noop(4);
|
var ser = SerializerFixedBinaryLength.noop(4);
|
||||||
var itemKey = new byte[]{0, 1, 2, 3};
|
var itemKey = new byte[]{0, 1, 2, 3};
|
||||||
var newValue = new byte[]{4, 5, 6, 7};
|
var newValue = new byte[]{4, 5, 6, 7};
|
||||||
var itemKeyBuffer = Unpooled.wrappedBuffer(itemKey);
|
var itemKeyBuffer = Unpooled.wrappedBuffer(itemKey);
|
||||||
@ -90,7 +90,7 @@ public class Example {
|
|||||||
|
|
||||||
private static Mono<Void> testPutValueAndGetPrevious() {
|
private static Mono<Void> testPutValueAndGetPrevious() {
|
||||||
var ssg = new SubStageGetterSingleBytes();
|
var ssg = new SubStageGetterSingleBytes();
|
||||||
var ser = FixedLengthSerializer.noop(4);
|
var ser = SerializerFixedBinaryLength.noop(4);
|
||||||
var itemKey = new byte[]{0, 1, 2, 3};
|
var itemKey = new byte[]{0, 1, 2, 3};
|
||||||
var newValue = new byte[]{4, 5, 6, 7};
|
var newValue = new byte[]{4, 5, 6, 7};
|
||||||
var itemKeyBuffer = Unpooled.wrappedBuffer(itemKey);
|
var itemKeyBuffer = Unpooled.wrappedBuffer(itemKey);
|
||||||
@ -117,7 +117,7 @@ public class Example {
|
|||||||
|
|
||||||
private static Mono<Void> testPutValue() {
|
private static Mono<Void> testPutValue() {
|
||||||
var ssg = new SubStageGetterSingleBytes();
|
var ssg = new SubStageGetterSingleBytes();
|
||||||
var ser = FixedLengthSerializer.noop(4);
|
var ser = SerializerFixedBinaryLength.noop(4);
|
||||||
var itemKey = new byte[]{0, 1, 2, 3};
|
var itemKey = new byte[]{0, 1, 2, 3};
|
||||||
var newValue = new byte[]{4, 5, 6, 7};
|
var newValue = new byte[]{4, 5, 6, 7};
|
||||||
var itemKeyBuffer = Unpooled.wrappedBuffer(itemKey);
|
var itemKeyBuffer = Unpooled.wrappedBuffer(itemKey);
|
||||||
@ -140,7 +140,7 @@ public class Example {
|
|||||||
|
|
||||||
private static Mono<Void> testPutMulti() {
|
private static Mono<Void> testPutMulti() {
|
||||||
var ssg = new SubStageGetterSingleBytes();
|
var ssg = new SubStageGetterSingleBytes();
|
||||||
var ser = FixedLengthSerializer.noop(4);
|
var ser = SerializerFixedBinaryLength.noop(4);
|
||||||
HashMap<ByteBuf, byte[]> keysToPut = new HashMap<>();
|
HashMap<ByteBuf, byte[]> keysToPut = new HashMap<>();
|
||||||
for (int i = 0; i < batchSize; i++) {
|
for (int i = 0; i < batchSize; i++) {
|
||||||
keysToPut.put(Unpooled.wrappedBuffer(Ints.toByteArray(i * 3)), Ints.toByteArray(i * 11));
|
keysToPut.put(Unpooled.wrappedBuffer(Ints.toByteArray(i * 3)), Ints.toByteArray(i * 11));
|
||||||
@ -158,7 +158,7 @@ public class Example {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Mono<Void> rangeTestAtPut() {
|
private static Mono<Void> rangeTestAtPut() {
|
||||||
var ser = FixedLengthSerializer.noop(4);
|
var ser = SerializerFixedBinaryLength.noop(4);
|
||||||
var vser = Serializer.noopBytes();
|
var vser = Serializer.noopBytes();
|
||||||
var itemKey = new byte[]{0, 1, 2, 3};
|
var itemKey = new byte[]{0, 1, 2, 3};
|
||||||
var newValue = new byte[]{4, 5, 6, 7};
|
var newValue = new byte[]{4, 5, 6, 7};
|
||||||
@ -186,7 +186,7 @@ public class Example {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Mono<Void> rangeTestPutValueAndGetPrevious() {
|
private static Mono<Void> rangeTestPutValueAndGetPrevious() {
|
||||||
var ser = FixedLengthSerializer.noop(4);
|
var ser = SerializerFixedBinaryLength.noop(4);
|
||||||
var vser = Serializer.noopBytes();
|
var vser = Serializer.noopBytes();
|
||||||
var itemKey = new byte[]{0, 1, 2, 3};
|
var itemKey = new byte[]{0, 1, 2, 3};
|
||||||
var newValue = new byte[]{4, 5, 6, 7};
|
var newValue = new byte[]{4, 5, 6, 7};
|
||||||
@ -213,7 +213,7 @@ public class Example {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Mono<Void> rangeTestPutValue() {
|
private static Mono<Void> rangeTestPutValue() {
|
||||||
var ser = FixedLengthSerializer.noop(4);
|
var ser = SerializerFixedBinaryLength.noop(4);
|
||||||
var vser = Serializer.noopBytes();
|
var vser = Serializer.noopBytes();
|
||||||
var itemKey = new byte[]{0, 1, 2, 3};
|
var itemKey = new byte[]{0, 1, 2, 3};
|
||||||
var newValue = new byte[]{4, 5, 6, 7};
|
var newValue = new byte[]{4, 5, 6, 7};
|
||||||
@ -236,7 +236,7 @@ public class Example {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Mono<Void> rangeTestPutMulti() {
|
private static Mono<Void> rangeTestPutMulti() {
|
||||||
var ser = FixedLengthSerializer.noop(4);
|
var ser = SerializerFixedBinaryLength.noop(4);
|
||||||
var vser = Serializer.noopBytes();
|
var vser = Serializer.noopBytes();
|
||||||
HashMap<ByteBuf, byte[]> keysToPut = new HashMap<>();
|
HashMap<ByteBuf, byte[]> keysToPut = new HashMap<>();
|
||||||
for (int i = 0; i < batchSize; i++) {
|
for (int i = 0; i < batchSize; i++) {
|
||||||
|
@ -20,19 +20,19 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
|
|
||||||
private final Serializer<U> valueSerializer;
|
private final Serializer<U> valueSerializer;
|
||||||
|
|
||||||
protected DatabaseMapDictionary(LLDictionary dictionary, byte[] prefixKey, FixedLengthSerializer<T> keySuffixSerializer, Serializer<U> valueSerializer) {
|
protected DatabaseMapDictionary(LLDictionary dictionary, byte[] prefixKey, SerializerFixedBinaryLength<T> keySuffixSerializer, Serializer<U> valueSerializer) {
|
||||||
super(dictionary, new SubStageGetterSingle<>(valueSerializer), keySuffixSerializer, prefixKey, 0);
|
super(dictionary, new SubStageGetterSingle<>(valueSerializer), keySuffixSerializer, prefixKey, 0);
|
||||||
this.valueSerializer = valueSerializer;
|
this.valueSerializer = valueSerializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U> DatabaseMapDictionary<T, U> simple(LLDictionary dictionary,
|
public static <T, U> DatabaseMapDictionary<T, U> simple(LLDictionary dictionary,
|
||||||
FixedLengthSerializer<T> keySerializer,
|
SerializerFixedBinaryLength<T> keySerializer,
|
||||||
Serializer<U> valueSerializer) {
|
Serializer<U> valueSerializer) {
|
||||||
return new DatabaseMapDictionary<>(dictionary, EMPTY_BYTES, keySerializer, valueSerializer);
|
return new DatabaseMapDictionary<>(dictionary, EMPTY_BYTES, keySerializer, valueSerializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U> DatabaseMapDictionary<T, U> tail(LLDictionary dictionary,
|
public static <T, U> DatabaseMapDictionary<T, U> tail(LLDictionary dictionary,
|
||||||
FixedLengthSerializer<T> keySuffixSerializer,
|
SerializerFixedBinaryLength<T> keySuffixSerializer,
|
||||||
Serializer<U> valueSerializer,
|
Serializer<U> valueSerializer,
|
||||||
byte[] prefixKey) {
|
byte[] prefixKey) {
|
||||||
return new DatabaseMapDictionary<>(dictionary, prefixKey, keySuffixSerializer, valueSerializer);
|
return new DatabaseMapDictionary<>(dictionary, prefixKey, keySuffixSerializer, valueSerializer);
|
||||||
|
@ -20,7 +20,7 @@ public class DatabaseMapDictionaryDeep<T, U, US extends DatabaseStage<U>> implem
|
|||||||
public static final byte[] EMPTY_BYTES = new byte[0];
|
public static final byte[] EMPTY_BYTES = new byte[0];
|
||||||
protected final LLDictionary dictionary;
|
protected final LLDictionary dictionary;
|
||||||
protected final SubStageGetter<U, US> subStageGetter;
|
protected final SubStageGetter<U, US> subStageGetter;
|
||||||
protected final FixedLengthSerializer<T> keySuffixSerializer;
|
protected final SerializerFixedBinaryLength<T> keySuffixSerializer;
|
||||||
protected final byte[] keyPrefix;
|
protected final byte[] keyPrefix;
|
||||||
protected final int keySuffixLength;
|
protected final int keySuffixLength;
|
||||||
protected final int keyExtLength;
|
protected final int keyExtLength;
|
||||||
@ -73,20 +73,20 @@ public class DatabaseMapDictionaryDeep<T, U, US extends DatabaseStage<U>> implem
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public static <T, U> DatabaseMapDictionaryDeep<T, U, DatabaseStageEntry<U>> simple(LLDictionary dictionary,
|
public static <T, U> DatabaseMapDictionaryDeep<T, U, DatabaseStageEntry<U>> simple(LLDictionary dictionary,
|
||||||
SubStageGetterSingle<U> subStageGetter,
|
SubStageGetterSingle<U> subStageGetter,
|
||||||
FixedLengthSerializer<T> keySerializer) {
|
SerializerFixedBinaryLength<T> keySerializer) {
|
||||||
return new DatabaseMapDictionaryDeep<>(dictionary, subStageGetter, keySerializer, EMPTY_BYTES, 0);
|
return new DatabaseMapDictionaryDeep<>(dictionary, subStageGetter, keySerializer, EMPTY_BYTES, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U, US extends DatabaseStage<U>> DatabaseMapDictionaryDeep<T, U, US> deepTail(LLDictionary dictionary,
|
public static <T, U, US extends DatabaseStage<U>> DatabaseMapDictionaryDeep<T, U, US> deepTail(LLDictionary dictionary,
|
||||||
SubStageGetter<U, US> subStageGetter,
|
SubStageGetter<U, US> subStageGetter,
|
||||||
FixedLengthSerializer<T> keySerializer,
|
SerializerFixedBinaryLength<T> keySerializer,
|
||||||
int keyExtLength) {
|
int keyExtLength) {
|
||||||
return new DatabaseMapDictionaryDeep<>(dictionary, subStageGetter, keySerializer, EMPTY_BYTES, keyExtLength);
|
return new DatabaseMapDictionaryDeep<>(dictionary, subStageGetter, keySerializer, EMPTY_BYTES, keyExtLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U, US extends DatabaseStage<U>> DatabaseMapDictionaryDeep<T, U, US> deepIntermediate(LLDictionary dictionary,
|
public static <T, U, US extends DatabaseStage<U>> DatabaseMapDictionaryDeep<T, U, US> deepIntermediate(LLDictionary dictionary,
|
||||||
SubStageGetter<U, US> subStageGetter,
|
SubStageGetter<U, US> subStageGetter,
|
||||||
FixedLengthSerializer<T> keySuffixSerializer,
|
SerializerFixedBinaryLength<T> keySuffixSerializer,
|
||||||
byte[] prefixKey,
|
byte[] prefixKey,
|
||||||
int keyExtLength) {
|
int keyExtLength) {
|
||||||
return new DatabaseMapDictionaryDeep<>(dictionary, subStageGetter, keySuffixSerializer, prefixKey, keyExtLength);
|
return new DatabaseMapDictionaryDeep<>(dictionary, subStageGetter, keySuffixSerializer, prefixKey, keyExtLength);
|
||||||
@ -94,14 +94,14 @@ public class DatabaseMapDictionaryDeep<T, U, US extends DatabaseStage<U>> implem
|
|||||||
|
|
||||||
protected DatabaseMapDictionaryDeep(LLDictionary dictionary,
|
protected DatabaseMapDictionaryDeep(LLDictionary dictionary,
|
||||||
SubStageGetter<U, US> subStageGetter,
|
SubStageGetter<U, US> subStageGetter,
|
||||||
FixedLengthSerializer<T> keySuffixSerializer,
|
SerializerFixedBinaryLength<T> keySuffixSerializer,
|
||||||
byte[] prefixKey,
|
byte[] prefixKey,
|
||||||
int keyExtLength) {
|
int keyExtLength) {
|
||||||
this.dictionary = dictionary;
|
this.dictionary = dictionary;
|
||||||
this.subStageGetter = subStageGetter;
|
this.subStageGetter = subStageGetter;
|
||||||
this.keySuffixSerializer = keySuffixSerializer;
|
this.keySuffixSerializer = keySuffixSerializer;
|
||||||
this.keyPrefix = prefixKey;
|
this.keyPrefix = prefixKey;
|
||||||
this.keySuffixLength = keySuffixSerializer.getLength();
|
this.keySuffixLength = keySuffixSerializer.getSerializedBinaryLength();
|
||||||
this.keyExtLength = keyExtLength;
|
this.keyExtLength = keyExtLength;
|
||||||
byte[] firstKey = firstKey(keyPrefix, keyPrefix.length, keySuffixLength, keyExtLength);
|
byte[] firstKey = firstKey(keyPrefix, keyPrefix.length, keySuffixLength, keyExtLength);
|
||||||
byte[] lastKey = lastKey(keyPrefix, keyPrefix.length, keySuffixLength, keyExtLength);
|
byte[] lastKey = lastKey(keyPrefix, keyPrefix.length, keySuffixLength, keyExtLength);
|
||||||
|
@ -2,12 +2,12 @@ package it.cavallium.dbengine.database.collections;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
public interface FixedLengthSerializer<B> extends Serializer<B> {
|
public interface SerializerFixedBinaryLength<B> extends Serializer<B> {
|
||||||
|
|
||||||
int getLength();
|
int getSerializedBinaryLength();
|
||||||
|
|
||||||
static FixedLengthSerializer<ByteBuf> noop(int length) {
|
static SerializerFixedBinaryLength<ByteBuf> noop(int length) {
|
||||||
return new FixedLengthSerializer<>() {
|
return new SerializerFixedBinaryLength<>() {
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf deserialize(ByteBuf serialized) {
|
public ByteBuf deserialize(ByteBuf serialized) {
|
||||||
return serialized.readSlice(length);
|
return serialized.readSlice(length);
|
||||||
@ -19,7 +19,7 @@ public interface FixedLengthSerializer<B> extends Serializer<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLength() {
|
public int getSerializedBinaryLength() {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -9,10 +9,10 @@ import reactor.core.publisher.Mono;
|
|||||||
|
|
||||||
public class SubStageGetterMap<T, U> implements SubStageGetter<Map<T, U>, DatabaseStageEntry<Map<T, U>>> {
|
public class SubStageGetterMap<T, U> implements SubStageGetter<Map<T, U>, DatabaseStageEntry<Map<T, U>>> {
|
||||||
|
|
||||||
private final FixedLengthSerializer<T> keySerializer;
|
private final SerializerFixedBinaryLength<T> keySerializer;
|
||||||
private final Serializer<U> valueSerializer;
|
private final Serializer<U> valueSerializer;
|
||||||
|
|
||||||
public SubStageGetterMap(FixedLengthSerializer<T> keySerializer, Serializer<U> valueSerializer) {
|
public SubStageGetterMap(SerializerFixedBinaryLength<T> keySerializer, Serializer<U> valueSerializer) {
|
||||||
this.keySerializer = keySerializer;
|
this.keySerializer = keySerializer;
|
||||||
this.valueSerializer = valueSerializer;
|
this.valueSerializer = valueSerializer;
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@ public class SubStageGetterMapDeep<T, U, US extends DatabaseStage<U>> implements
|
|||||||
SubStageGetter<Map<T, U>, DatabaseStageEntry<Map<T, U>>> {
|
SubStageGetter<Map<T, U>, DatabaseStageEntry<Map<T, U>>> {
|
||||||
|
|
||||||
private final SubStageGetter<U, US> subStageGetter;
|
private final SubStageGetter<U, US> subStageGetter;
|
||||||
private final FixedLengthSerializer<T> keySerializer;
|
private final SerializerFixedBinaryLength<T> keySerializer;
|
||||||
private final int keyExtLength;
|
private final int keyExtLength;
|
||||||
|
|
||||||
public SubStageGetterMapDeep(SubStageGetter<U, US> subStageGetter,
|
public SubStageGetterMapDeep(SubStageGetter<U, US> subStageGetter,
|
||||||
FixedLengthSerializer<T> keySerializer,
|
SerializerFixedBinaryLength<T> keySerializer,
|
||||||
int keyExtLength) {
|
int keyExtLength) {
|
||||||
this.subStageGetter = subStageGetter;
|
this.subStageGetter = subStageGetter;
|
||||||
this.keySerializer = keySerializer;
|
this.keySerializer = keySerializer;
|
||||||
|
Loading…
Reference in New Issue
Block a user