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

63 lines
2.1 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;
import io.netty5.buffer.api.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,
2021-09-23 20:57:28 +02:00
SerializerFixedBinaryLength<T> keySuffixSerializer,
2021-10-01 19:17:33 +02:00
Runnable onClose) {
2022-05-21 01:06:55 +02:00
super(dictionary,
prefixKeySupplier,
keySuffixSerializer,
DatabaseEmpty.nothingSerializer(dictionary.getAllocator()),
onClose
);
2021-02-04 00:48:49 +01:00
}
public static <T> DatabaseSetDictionary<T> simple(LLDictionary dictionary,
2021-09-23 20:57:28 +02:00
SerializerFixedBinaryLength<T> keySerializer,
2021-10-01 19:17:33 +02:00
Runnable onClose) {
2021-11-08 16:33:41 +01:00
return new DatabaseSetDictionary<>(dictionary, null, keySerializer, onClose);
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,
2021-09-23 20:57:28 +02:00
SerializerFixedBinaryLength<T> keySuffixSerializer,
2021-10-01 19:17:33 +02:00
Runnable onClose) {
2022-05-21 01:06:55 +02:00
return new DatabaseSetDictionary<>(dictionary, prefixKeySupplier, keySuffixSerializer, onClose);
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);
}
}