Update Example.java, DatabaseMapDictionary.java, and 5 more files...

This commit is contained in:
Andrea Cavalli 2021-02-01 10:52:33 +01:00
parent 554facde13
commit 2bd69f0331
6 changed files with 27 additions and 27 deletions

View File

@ -7,7 +7,7 @@ import it.cavallium.dbengine.database.Column;
import it.cavallium.dbengine.database.LLKeyValueDatabase;
import it.cavallium.dbengine.database.collections.DatabaseMapDictionary;
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.SubStageGetterSingleBytes;
import it.cavallium.dbengine.database.disk.LLLocalDatabaseConnection;
@ -62,7 +62,7 @@ public class Example {
private static Mono<Void> testAtPut() {
var ssg = new SubStageGetterSingleBytes();
var ser = FixedLengthSerializer.noop(4);
var ser = SerializerFixedBinaryLength.noop(4);
var itemKey = new byte[]{0, 1, 2, 3};
var newValue = new byte[]{4, 5, 6, 7};
var itemKeyBuffer = Unpooled.wrappedBuffer(itemKey);
@ -90,7 +90,7 @@ public class Example {
private static Mono<Void> testPutValueAndGetPrevious() {
var ssg = new SubStageGetterSingleBytes();
var ser = FixedLengthSerializer.noop(4);
var ser = SerializerFixedBinaryLength.noop(4);
var itemKey = new byte[]{0, 1, 2, 3};
var newValue = new byte[]{4, 5, 6, 7};
var itemKeyBuffer = Unpooled.wrappedBuffer(itemKey);
@ -117,7 +117,7 @@ public class Example {
private static Mono<Void> testPutValue() {
var ssg = new SubStageGetterSingleBytes();
var ser = FixedLengthSerializer.noop(4);
var ser = SerializerFixedBinaryLength.noop(4);
var itemKey = new byte[]{0, 1, 2, 3};
var newValue = new byte[]{4, 5, 6, 7};
var itemKeyBuffer = Unpooled.wrappedBuffer(itemKey);
@ -140,7 +140,7 @@ public class Example {
private static Mono<Void> testPutMulti() {
var ssg = new SubStageGetterSingleBytes();
var ser = FixedLengthSerializer.noop(4);
var ser = SerializerFixedBinaryLength.noop(4);
HashMap<ByteBuf, byte[]> keysToPut = new HashMap<>();
for (int i = 0; i < batchSize; i++) {
keysToPut.put(Unpooled.wrappedBuffer(Ints.toByteArray(i * 3)), Ints.toByteArray(i * 11));
@ -158,7 +158,7 @@ public class Example {
}
private static Mono<Void> rangeTestAtPut() {
var ser = FixedLengthSerializer.noop(4);
var ser = SerializerFixedBinaryLength.noop(4);
var vser = Serializer.noopBytes();
var itemKey = new byte[]{0, 1, 2, 3};
var newValue = new byte[]{4, 5, 6, 7};
@ -186,7 +186,7 @@ public class Example {
}
private static Mono<Void> rangeTestPutValueAndGetPrevious() {
var ser = FixedLengthSerializer.noop(4);
var ser = SerializerFixedBinaryLength.noop(4);
var vser = Serializer.noopBytes();
var itemKey = new byte[]{0, 1, 2, 3};
var newValue = new byte[]{4, 5, 6, 7};
@ -213,7 +213,7 @@ public class Example {
}
private static Mono<Void> rangeTestPutValue() {
var ser = FixedLengthSerializer.noop(4);
var ser = SerializerFixedBinaryLength.noop(4);
var vser = Serializer.noopBytes();
var itemKey = new byte[]{0, 1, 2, 3};
var newValue = new byte[]{4, 5, 6, 7};
@ -236,7 +236,7 @@ public class Example {
}
private static Mono<Void> rangeTestPutMulti() {
var ser = FixedLengthSerializer.noop(4);
var ser = SerializerFixedBinaryLength.noop(4);
var vser = Serializer.noopBytes();
HashMap<ByteBuf, byte[]> keysToPut = new HashMap<>();
for (int i = 0; i < batchSize; i++) {

View File

@ -20,19 +20,19 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
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);
this.valueSerializer = valueSerializer;
}
public static <T, U> DatabaseMapDictionary<T, U> simple(LLDictionary dictionary,
FixedLengthSerializer<T> keySerializer,
SerializerFixedBinaryLength<T> keySerializer,
Serializer<U> valueSerializer) {
return new DatabaseMapDictionary<>(dictionary, EMPTY_BYTES, keySerializer, valueSerializer);
}
public static <T, U> DatabaseMapDictionary<T, U> tail(LLDictionary dictionary,
FixedLengthSerializer<T> keySuffixSerializer,
SerializerFixedBinaryLength<T> keySuffixSerializer,
Serializer<U> valueSerializer,
byte[] prefixKey) {
return new DatabaseMapDictionary<>(dictionary, prefixKey, keySuffixSerializer, valueSerializer);

View File

@ -20,7 +20,7 @@ public class DatabaseMapDictionaryDeep<T, U, US extends DatabaseStage<U>> implem
public static final byte[] EMPTY_BYTES = new byte[0];
protected final LLDictionary dictionary;
protected final SubStageGetter<U, US> subStageGetter;
protected final FixedLengthSerializer<T> keySuffixSerializer;
protected final SerializerFixedBinaryLength<T> keySuffixSerializer;
protected final byte[] keyPrefix;
protected final int keySuffixLength;
protected final int keyExtLength;
@ -73,20 +73,20 @@ public class DatabaseMapDictionaryDeep<T, U, US extends DatabaseStage<U>> implem
@Deprecated
public static <T, U> DatabaseMapDictionaryDeep<T, U, DatabaseStageEntry<U>> simple(LLDictionary dictionary,
SubStageGetterSingle<U> subStageGetter,
FixedLengthSerializer<T> keySerializer) {
SerializerFixedBinaryLength<T> keySerializer) {
return new DatabaseMapDictionaryDeep<>(dictionary, subStageGetter, keySerializer, EMPTY_BYTES, 0);
}
public static <T, U, US extends DatabaseStage<U>> DatabaseMapDictionaryDeep<T, U, US> deepTail(LLDictionary dictionary,
SubStageGetter<U, US> subStageGetter,
FixedLengthSerializer<T> keySerializer,
SerializerFixedBinaryLength<T> keySerializer,
int 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,
SubStageGetter<U, US> subStageGetter,
FixedLengthSerializer<T> keySuffixSerializer,
SerializerFixedBinaryLength<T> keySuffixSerializer,
byte[] prefixKey,
int 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,
SubStageGetter<U, US> subStageGetter,
FixedLengthSerializer<T> keySuffixSerializer,
SerializerFixedBinaryLength<T> keySuffixSerializer,
byte[] prefixKey,
int keyExtLength) {
this.dictionary = dictionary;
this.subStageGetter = subStageGetter;
this.keySuffixSerializer = keySuffixSerializer;
this.keyPrefix = prefixKey;
this.keySuffixLength = keySuffixSerializer.getLength();
this.keySuffixLength = keySuffixSerializer.getSerializedBinaryLength();
this.keyExtLength = keyExtLength;
byte[] firstKey = firstKey(keyPrefix, keyPrefix.length, keySuffixLength, keyExtLength);
byte[] lastKey = lastKey(keyPrefix, keyPrefix.length, keySuffixLength, keyExtLength);

View File

@ -2,12 +2,12 @@ package it.cavallium.dbengine.database.collections;
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) {
return new FixedLengthSerializer<>() {
static SerializerFixedBinaryLength<ByteBuf> noop(int length) {
return new SerializerFixedBinaryLength<>() {
@Override
public ByteBuf deserialize(ByteBuf serialized) {
return serialized.readSlice(length);
@ -19,7 +19,7 @@ public interface FixedLengthSerializer<B> extends Serializer<B> {
}
@Override
public int getLength() {
public int getSerializedBinaryLength() {
return length;
}
};

View File

@ -9,10 +9,10 @@ import reactor.core.publisher.Mono;
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;
public SubStageGetterMap(FixedLengthSerializer<T> keySerializer, Serializer<U> valueSerializer) {
public SubStageGetterMap(SerializerFixedBinaryLength<T> keySerializer, Serializer<U> valueSerializer) {
this.keySerializer = keySerializer;
this.valueSerializer = valueSerializer;
}

View File

@ -11,11 +11,11 @@ public class SubStageGetterMapDeep<T, U, US extends DatabaseStage<U>> implements
SubStageGetter<Map<T, U>, DatabaseStageEntry<Map<T, U>>> {
private final SubStageGetter<U, US> subStageGetter;
private final FixedLengthSerializer<T> keySerializer;
private final SerializerFixedBinaryLength<T> keySerializer;
private final int keyExtLength;
public SubStageGetterMapDeep(SubStageGetter<U, US> subStageGetter,
FixedLengthSerializer<T> keySerializer,
SerializerFixedBinaryLength<T> keySerializer,
int keyExtLength) {
this.subStageGetter = subStageGetter;
this.keySerializer = keySerializer;