package it.cavallium.dbengine.database; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import java.util.List; import java.util.Map.Entry; import java.util.function.Function; import org.jetbrains.annotations.Nullable; import org.warp.commonutils.concurrency.atomicity.NotAtomic; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.util.function.Tuple2; @SuppressWarnings("unused") @NotAtomic public interface LLDictionary extends LLKeyValueDatabaseStructure { String getColumnName(); ByteBufAllocator getAllocator(); Mono get(@Nullable LLSnapshot snapshot, ByteBuf key, boolean existsAlmostCertainly); default Mono get(@Nullable LLSnapshot snapshot, ByteBuf key) { return get(snapshot, key, false); } Mono put(ByteBuf key, ByteBuf value, LLDictionaryResultType resultType); Mono getUpdateMode(); default Mono update(ByteBuf key, Function<@Nullable ByteBuf, @Nullable ByteBuf> updater, UpdateReturnMode updateReturnMode, boolean existsAlmostCertainly) { return this .updateAndGetDelta(key, updater, existsAlmostCertainly) .transform(prev -> LLUtils.resolveDelta(prev, updateReturnMode)); } default Mono update(ByteBuf key, Function<@Nullable ByteBuf, @Nullable ByteBuf> updater, UpdateReturnMode returnMode) { return update(key, updater, returnMode, false); } Mono> updateAndGetDelta(ByteBuf key, Function<@Nullable ByteBuf, @Nullable ByteBuf> updater, boolean existsAlmostCertainly); default Mono> updateAndGetDelta(ByteBuf key, Function<@Nullable ByteBuf, @Nullable ByteBuf> updater) { return updateAndGetDelta(key, updater, false); } Mono clear(); Mono remove(ByteBuf key, LLDictionaryResultType resultType); Flux> getMulti(@Nullable LLSnapshot snapshot, Flux keys, boolean existsAlmostCertainly); default Flux> getMulti(@Nullable LLSnapshot snapshot, Flux keys) { return getMulti(snapshot, keys, false); } Flux> putMulti(Flux> entries, boolean getOldValues); Flux> getRange(@Nullable LLSnapshot snapshot, LLRange range, boolean existsAlmostCertainly); default Flux> getRange(@Nullable LLSnapshot snapshot, LLRange range) { return getRange(snapshot, range, false); } Flux>> getRangeGrouped(@Nullable LLSnapshot snapshot, LLRange range, int prefixLength, boolean existsAlmostCertainly); default Flux>> getRangeGrouped(@Nullable LLSnapshot snapshot, LLRange range, int prefixLength) { return getRangeGrouped(snapshot, range, prefixLength, false); } Flux getRangeKeys(@Nullable LLSnapshot snapshot, LLRange range); Flux> getRangeKeysGrouped(@Nullable LLSnapshot snapshot, LLRange range, int prefixLength); Flux getRangeKeyPrefixes(@Nullable LLSnapshot snapshot, LLRange range, int prefixLength); Mono setRange(LLRange range, Flux> entries); default Mono replaceRange(LLRange range, boolean canKeysChange, Function, Mono>> entriesReplacer, boolean existsAlmostCertainly) { return Mono.defer(() -> { if (canKeysChange) { return this .setRange(range, this .getRange(null, range, existsAlmostCertainly) .flatMap(entriesReplacer) ); } else { return this .putMulti(this .getRange(null, range, existsAlmostCertainly) .flatMap(entriesReplacer), false) .then(); } }); } default Mono replaceRange(LLRange range, boolean canKeysChange, Function, Mono>> entriesReplacer) { return replaceRange(range, canKeysChange, entriesReplacer, false); } Mono isRangeEmpty(@Nullable LLSnapshot snapshot, LLRange range); Mono sizeRange(@Nullable LLSnapshot snapshot, LLRange range, boolean fast); Mono> getOne(@Nullable LLSnapshot snapshot, LLRange range); Mono getOneKey(@Nullable LLSnapshot snapshot, LLRange range); Mono> removeOne(LLRange range); }