2021-02-04 00:48:49 +01:00
|
|
|
package it.cavallium.dbengine.database.collections;
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
import io.netty.buffer.api.Buffer;
|
2021-02-04 00:48:49 +01:00
|
|
|
import it.cavallium.dbengine.client.CompositeSnapshot;
|
|
|
|
import it.cavallium.dbengine.database.LLDictionary;
|
|
|
|
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")
|
2021-05-11 21:59:05 +02:00
|
|
|
public class DatabaseSetDictionary<T> extends DatabaseMapDictionary<T, Nothing> {
|
2021-02-04 00:48:49 +01:00
|
|
|
|
|
|
|
protected DatabaseSetDictionary(LLDictionary dictionary,
|
2021-08-29 23:18:03 +02:00
|
|
|
Buffer prefixKey,
|
|
|
|
SerializerFixedBinaryLength<T, Buffer> keySuffixSerializer) {
|
2021-05-11 21:59:05 +02:00
|
|
|
super(dictionary, prefixKey, keySuffixSerializer, DatabaseEmpty.NOTHING_SERIALIZER);
|
2021-02-04 00:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> DatabaseSetDictionary<T> simple(LLDictionary dictionary,
|
2021-08-29 23:18:03 +02:00
|
|
|
SerializerFixedBinaryLength<T, Buffer> keySerializer) {
|
2021-08-27 02:49:51 +02:00
|
|
|
var buf = dictionary.getAllocator().buffer(0);
|
|
|
|
try {
|
|
|
|
return new DatabaseSetDictionary<>(dictionary, buf, keySerializer);
|
|
|
|
} finally {
|
|
|
|
buf.release();
|
|
|
|
}
|
2021-02-04 00:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> DatabaseSetDictionary<T> tail(LLDictionary dictionary,
|
2021-08-29 23:18:03 +02:00
|
|
|
Buffer prefixKey,
|
|
|
|
SerializerFixedBinaryLength<T, Buffer> keySuffixSerializer) {
|
2021-02-04 00:48:49 +01:00
|
|
|
return new DatabaseSetDictionary<>(dictionary, prefixKey, keySuffixSerializer);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|