2021-04-12 17:09:55 +02: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-04-12 17:09:55 +02: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-04-12 17:09:55 +02:00
|
|
|
import it.cavallium.dbengine.database.collections.DatabaseEmpty.Nothing;
|
|
|
|
import it.cavallium.dbengine.database.serialization.Serializer;
|
|
|
|
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.function.Function;
|
2021-09-23 11:30:44 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2021-04-12 17:09:55 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public class DatabaseSetDictionaryHashed<T, TH> extends DatabaseMapDictionaryHashed<T, Nothing, TH> {
|
|
|
|
|
|
|
|
protected DatabaseSetDictionaryHashed(LLDictionary dictionary,
|
2021-09-23 11:30:44 +02:00
|
|
|
@NotNull Send<Buffer> prefixKey,
|
2021-09-01 00:01:56 +02:00
|
|
|
Serializer<T> keySuffixSerializer,
|
2021-04-12 17:09:55 +02:00
|
|
|
Function<T, TH> keySuffixHashFunction,
|
2021-09-01 00:01:56 +02:00
|
|
|
SerializerFixedBinaryLength<TH> keySuffixHashSerializer) {
|
2021-04-12 17:09:55 +02:00
|
|
|
super(dictionary,
|
|
|
|
prefixKey,
|
|
|
|
keySuffixSerializer,
|
2021-08-31 09:14:46 +02:00
|
|
|
DatabaseEmpty.nothingSerializer(dictionary.getAllocator()),
|
2021-04-12 17:09:55 +02:00
|
|
|
keySuffixHashFunction,
|
|
|
|
keySuffixHashSerializer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T, TH> DatabaseSetDictionaryHashed<T, TH> simple(LLDictionary dictionary,
|
2021-09-01 00:01:56 +02:00
|
|
|
Serializer<T> keySerializer,
|
2021-04-12 17:09:55 +02:00
|
|
|
Function<T, TH> keyHashFunction,
|
2021-09-01 00:01:56 +02:00
|
|
|
SerializerFixedBinaryLength<TH> keyHashSerializer) {
|
2021-04-12 17:09:55 +02:00
|
|
|
return new DatabaseSetDictionaryHashed<>(dictionary,
|
2021-09-23 11:30:44 +02:00
|
|
|
LLUtils.empty(dictionary.getAllocator()),
|
2021-04-12 17:09:55 +02:00
|
|
|
keySerializer,
|
|
|
|
keyHashFunction,
|
|
|
|
keyHashSerializer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T, TH> DatabaseSetDictionaryHashed<T, TH> tail(LLDictionary dictionary,
|
2021-08-31 09:14:46 +02:00
|
|
|
Send<Buffer> prefixKey,
|
2021-09-01 00:01:56 +02:00
|
|
|
Serializer<T> keySuffixSerializer,
|
2021-04-12 17:09:55 +02:00
|
|
|
Function<T, TH> keyHashFunction,
|
2021-09-01 00:01:56 +02:00
|
|
|
SerializerFixedBinaryLength<TH> keyHashSerializer) {
|
2021-04-12 17:09:55 +02:00
|
|
|
return new DatabaseSetDictionaryHashed<>(dictionary,
|
|
|
|
prefixKey,
|
|
|
|
keySuffixSerializer,
|
|
|
|
keyHashFunction,
|
|
|
|
keyHashSerializer
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|