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.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-08-22 18:20:05 +02:00
|
|
|
public class SubStageGetterMapDeep<T, U, US extends DatabaseStage<U>> implements
|
2021-12-18 18:16:56 +01:00
|
|
|
SubStageGetter<Object2ObjectSortedMap<T, U>, DatabaseMapDictionaryDeep<T, U, US>> {
|
2021-01-31 00:36:21 +01:00
|
|
|
|
|
|
|
private final SubStageGetter<U, US> subStageGetter;
|
2021-09-02 17:15:40 +02:00
|
|
|
private final SerializerFixedBinaryLength<T> keySerializer;
|
2021-01-31 00:36:21 +01:00
|
|
|
private final int keyExtLength;
|
|
|
|
|
2021-01-31 12:43:28 +01:00
|
|
|
public SubStageGetterMapDeep(SubStageGetter<U, US> subStageGetter,
|
2021-09-02 17:15:40 +02:00
|
|
|
SerializerFixedBinaryLength<T> keySerializer,
|
2021-08-28 22:42:51 +02:00
|
|
|
int keyExtLength) {
|
2021-01-31 00:36:21 +01:00
|
|
|
this.subStageGetter = subStageGetter;
|
2021-01-31 12:43:28 +01:00
|
|
|
this.keySerializer = keySerializer;
|
2021-01-31 00:36:21 +01:00
|
|
|
this.keyExtLength = keyExtLength;
|
2021-02-02 15:36:11 +01:00
|
|
|
assert keyExtConsistency();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean keyExtConsistency() {
|
|
|
|
if (subStageGetter instanceof SubStageGetterMapDeep) {
|
|
|
|
return keyExtLength == ((SubStageGetterMapDeep<?, ?, ?>) subStageGetter).getKeyBinaryLength();
|
|
|
|
} else if (subStageGetter instanceof SubStageGetterMap) {
|
|
|
|
return keyExtLength == ((SubStageGetterMap<?, ?>) subStageGetter).getKeyBinaryLength();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-31 00:36:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-02 18:42:18 +01:00
|
|
|
public Mono<DatabaseMapDictionaryDeep<T, U, US>> 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 DatabaseMapDictionaryDeep.deepIntermediate(dictionary,
|
|
|
|
prefixKey,
|
|
|
|
keySerializer,
|
|
|
|
subStageGetter,
|
|
|
|
keyExtLength,
|
|
|
|
null
|
|
|
|
);
|
2022-01-26 14:22:54 +01:00
|
|
|
});
|
2021-02-02 15:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getKeyBinaryLength() {
|
|
|
|
return keySerializer.getSerializedBinaryLength() + keyExtLength;
|
2021-01-31 00:36:21 +01:00
|
|
|
}
|
|
|
|
}
|