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

84 lines
2.5 KiB
Java
Raw Normal View History

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;
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-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-11-08 16:33:41 +01:00
@Nullable 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-23 20:57:28 +02:00
SerializerFixedBinaryLength<TH> keySuffixHashSerializer,
2021-10-01 19:17:33 +02:00
Runnable onClose) {
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,
2021-09-23 20:57:28 +02:00
keySuffixHashSerializer,
2021-10-01 19:17:33 +02:00
onClose
2021-04-12 17:09:55 +02:00
);
}
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-23 20:57:28 +02:00
SerializerFixedBinaryLength<TH> keyHashSerializer,
2021-10-01 19:17:33 +02:00
Runnable onClose) {
2021-04-12 17:09:55 +02:00
return new DatabaseSetDictionaryHashed<>(dictionary,
2021-11-08 16:33:41 +01:00
null,
2021-04-12 17:09:55 +02:00
keySerializer,
keyHashFunction,
2021-09-23 20:57:28 +02:00
keyHashSerializer,
2021-10-01 19:17:33 +02:00
onClose
2021-04-12 17:09:55 +02:00
);
}
public static <T, TH> DatabaseSetDictionaryHashed<T, TH> tail(LLDictionary dictionary,
2021-11-08 16:33:41 +01:00
@Nullable 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-10-01 19:17:33 +02:00
SerializerFixedBinaryLength<TH> keyHashSerializer,
Runnable onClose) {
2021-04-12 17:09:55 +02:00
return new DatabaseSetDictionaryHashed<>(dictionary,
prefixKey,
keySuffixSerializer,
keyHashFunction,
2021-09-23 20:57:28 +02:00
keyHashSerializer,
2021-10-01 19:17:33 +02:00
onClose
2021-04-12 17:09:55 +02: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);
}
}