2021-01-31 00:36:21 +01:00
|
|
|
package it.cavallium.dbengine.database.collections;
|
|
|
|
|
2023-02-09 23:34:25 +01:00
|
|
|
import it.cavallium.dbengine.buffers.Buf;
|
2021-01-31 00:36:21 +01:00
|
|
|
import it.cavallium.dbengine.client.CompositeSnapshot;
|
|
|
|
import it.cavallium.dbengine.database.LLDictionary;
|
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 org.jetbrains.annotations.Nullable;
|
|
|
|
|
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
|
2023-02-09 23:34:25 +01:00
|
|
|
public DatabaseMapDictionaryDeep<T, U, US> subStage(LLDictionary dictionary,
|
2021-01-31 00:36:21 +01:00
|
|
|
@Nullable CompositeSnapshot snapshot,
|
2023-02-09 23:34:25 +01:00
|
|
|
Buf prefixKey) {
|
|
|
|
return DatabaseMapDictionaryDeep.deepIntermediate(dictionary,
|
|
|
|
prefixKey,
|
2022-05-21 01:06:55 +02:00
|
|
|
keySerializer,
|
|
|
|
subStageGetter,
|
2022-07-19 23:45:39 +02:00
|
|
|
keyExtLength
|
2023-02-09 23:34:25 +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
|
|
|
}
|
|
|
|
}
|