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

56 lines
1.9 KiB
Java
Raw Normal View History

2021-02-04 00:48:49 +01:00
package it.cavallium.dbengine.database.collections;
2021-09-17 16:56:28 +02:00
import io.net5.buffer.api.Buffer;
2021-09-23 20:57:28 +02:00
import io.net5.buffer.api.Drop;
2021-09-17 16:56:28 +02:00
import io.net5.buffer.api.Send;
2021-02-04 00:48:49 +01:00
import it.cavallium.dbengine.client.CompositeSnapshot;
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;
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,
2021-08-31 09:14:46 +02:00
Send<Buffer> prefixKey,
2021-09-23 20:57:28 +02:00
SerializerFixedBinaryLength<T> keySuffixSerializer,
2021-10-01 19:17:33 +02:00
Runnable onClose) {
super(dictionary, prefixKey, 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) {
return new DatabaseSetDictionary<>(dictionary, LLUtils.empty(dictionary.getAllocator()), keySerializer, onClose);
2021-02-04 00:48:49 +01:00
}
public static <T> DatabaseSetDictionary<T> tail(LLDictionary dictionary,
2021-08-31 09:14:46 +02:00
Send<Buffer> prefixKey,
2021-09-23 20:57:28 +02:00
SerializerFixedBinaryLength<T> keySuffixSerializer,
2021-10-01 19:17:33 +02:00
Runnable onClose) {
return new DatabaseSetDictionary<>(dictionary, prefixKey, 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) {
var hm = new HashMap<T, Nothing>();
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);
}
}