2021-01-31 00:36:21 +01:00
|
|
|
package it.cavallium.dbengine.database.collections;
|
|
|
|
|
2021-09-17 16:56:28 +02:00
|
|
|
import io.net5.buffer.api.Buffer;
|
2021-11-08 16:33:41 +01:00
|
|
|
import io.net5.buffer.api.Resource;
|
2021-09-17 16:56:28 +02:00
|
|
|
import io.net5.buffer.api.Send;
|
2021-01-31 00:36:21 +01:00
|
|
|
import it.cavallium.dbengine.client.CompositeSnapshot;
|
|
|
|
import it.cavallium.dbengine.database.LLDictionary;
|
2021-09-23 20:57:28 +02:00
|
|
|
import it.cavallium.dbengine.database.LLUtils;
|
2021-02-02 19:40:37 +01:00
|
|
|
import it.cavallium.dbengine.database.serialization.Serializer;
|
|
|
|
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
2021-12-18 18:16:56 +01:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
|
2021-01-31 00:36:21 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
2021-12-18 18:16:56 +01:00
|
|
|
public class SubStageGetterMap<T, U> implements
|
|
|
|
SubStageGetter<Object2ObjectSortedMap<T, U>, DatabaseMapDictionary<T, U>> {
|
2021-01-31 00:36:21 +01:00
|
|
|
|
2021-09-02 17:15:40 +02:00
|
|
|
private final SerializerFixedBinaryLength<T> keySerializer;
|
|
|
|
private final Serializer<U> valueSerializer;
|
2021-01-31 00:36:21 +01:00
|
|
|
|
2021-09-02 17:15:40 +02:00
|
|
|
public SubStageGetterMap(SerializerFixedBinaryLength<T> keySerializer,
|
|
|
|
Serializer<U> valueSerializer) {
|
2021-01-31 19:52:47 +01:00
|
|
|
this.keySerializer = keySerializer;
|
|
|
|
this.valueSerializer = valueSerializer;
|
2021-01-31 00:36:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-02 18:42:18 +01:00
|
|
|
public Mono<DatabaseMapDictionary<T, U>> subStage(LLDictionary dictionary,
|
2021-01-31 00:36:21 +01:00
|
|
|
@Nullable CompositeSnapshot snapshot,
|
2021-08-31 09:14:46 +02:00
|
|
|
Mono<Send<Buffer>> prefixKeyMono) {
|
2021-11-08 16:33:41 +01:00
|
|
|
return prefixKeyMono.map(prefixKeyToReceive -> {
|
|
|
|
var prefixKey = prefixKeyToReceive.receive();
|
|
|
|
return DatabaseMapDictionary.tail(dictionary, prefixKey, keySerializer, valueSerializer, null);
|
|
|
|
}).doOnDiscard(Send.class, Send::close).doOnDiscard(Resource.class, Resource::close);
|
2021-02-02 15:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getKeyBinaryLength() {
|
|
|
|
return keySerializer.getSerializedBinaryLength();
|
2021-01-31 00:36:21 +01:00
|
|
|
}
|
|
|
|
}
|