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;
|
|
|
|
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;
|
|
|
|
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-31 09:14:46 +02:00
|
|
|
Send<Buffer> prefixKey,
|
2021-09-02 17:15:40 +02:00
|
|
|
SerializerFixedBinaryLength<T> keySuffixSerializer) {
|
2021-08-31 09:14:46 +02:00
|
|
|
super(dictionary, prefixKey, keySuffixSerializer, DatabaseEmpty.nothingSerializer(dictionary.getAllocator()));
|
2021-02-04 00:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> DatabaseSetDictionary<T> simple(LLDictionary dictionary,
|
2021-09-02 17:15:40 +02:00
|
|
|
SerializerFixedBinaryLength<T> keySerializer) {
|
2021-09-22 18:33:28 +02:00
|
|
|
return new DatabaseSetDictionary<>(dictionary, null, keySerializer);
|
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-02 17:15:40 +02:00
|
|
|
SerializerFixedBinaryLength<T> 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);
|
|
|
|
}
|
|
|
|
}
|