CavalliumDBEngine/src/main/java/it/cavallium/dbengine/database/collections/DatabaseSetDictionary.java

59 lines
2.0 KiB
Java
Raw Normal View History

2021-02-04 00:48:49 +01:00
package it.cavallium.dbengine.database.collections;
2022-03-16 13:47:56 +01:00
import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.api.Drop;
2022-07-15 02:44:50 +02:00
import io.netty5.util.Send;
2021-02-04 00:48:49 +01:00
import it.cavallium.dbengine.client.CompositeSnapshot;
2022-05-21 01:06:55 +02:00
import it.cavallium.dbengine.database.BufSupplier;
2021-02-04 00:48:49 +01:00
import it.cavallium.dbengine.database.LLDictionary;
2021-09-23 11:30:44 +02:00
import it.cavallium.dbengine.database.LLUtils;
2021-02-04 00:48:49 +01:00
import it.cavallium.dbengine.database.collections.DatabaseEmpty.Nothing;
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
2021-12-18 18:16:56 +01:00
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
2021-02-04 00:48:49 +01:00
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import reactor.core.publisher.Mono;
2021-04-03 19:09:06 +02:00
@SuppressWarnings("unused")
public class DatabaseSetDictionary<T> extends DatabaseMapDictionary<T, Nothing> {
2021-02-04 00:48:49 +01:00
protected DatabaseSetDictionary(LLDictionary dictionary,
2022-05-21 01:06:55 +02:00
BufSupplier prefixKeySupplier,
2022-07-19 23:45:39 +02:00
SerializerFixedBinaryLength<T> keySuffixSerializer) {
2022-05-21 01:06:55 +02:00
super(dictionary,
prefixKeySupplier,
keySuffixSerializer,
2022-07-19 23:45:39 +02:00
DatabaseEmpty.nothingSerializer(dictionary.getAllocator())
2022-05-21 01:06:55 +02:00
);
2021-02-04 00:48:49 +01:00
}
public static <T> DatabaseSetDictionary<T> simple(LLDictionary dictionary,
2022-07-19 23:45:39 +02:00
SerializerFixedBinaryLength<T> keySerializer) {
return new DatabaseSetDictionary<>(dictionary, null, keySerializer);
2021-02-04 00:48:49 +01:00
}
public static <T> DatabaseSetDictionary<T> tail(LLDictionary dictionary,
2022-05-21 01:06:55 +02:00
BufSupplier prefixKeySupplier,
2022-07-19 23:45:39 +02:00
SerializerFixedBinaryLength<T> keySuffixSerializer) {
return new DatabaseSetDictionary<>(dictionary, prefixKeySupplier, keySuffixSerializer);
2021-02-04 00:48:49 +01:00
}
public Mono<Set<T>> getKeySet(@Nullable CompositeSnapshot snapshot) {
return get(snapshot).map(Map::keySet);
}
public Mono<Set<T>> setAndGetPreviousKeySet(Set<T> value) {
2021-12-18 18:16:56 +01:00
var hm = new Object2ObjectLinkedOpenHashMap<T, Nothing>();
2021-02-04 00:48:49 +01:00
for (T t : value) {
hm.put(t, DatabaseEmpty.NOTHING);
}
return setAndGetPrevious(hm).map(Map::keySet);
}
public Mono<Set<T>> clearAndGetPreviousKeySet() {
return clearAndGetPrevious().map(Map::keySet);
}
}