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

74 lines
2.3 KiB
Java
Raw Normal View History

2021-04-12 17:09:55 +02:00
package it.cavallium.dbengine.database.collections;
import io.netty.buffer.ByteBuf;
2021-04-12 17:09:55 +02: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.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;
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,
ByteBuf prefixKey,
Serializer<T, ByteBuf> keySuffixSerializer,
2021-04-12 17:09:55 +02:00
Function<T, TH> keySuffixHashFunction,
SerializerFixedBinaryLength<TH, ByteBuf> keySuffixHashSerializer) {
2021-04-12 17:09:55 +02:00
super(dictionary,
prefixKey,
keySuffixSerializer,
DatabaseEmpty.NOTHING_SERIALIZER,
keySuffixHashFunction,
keySuffixHashSerializer
);
}
public static <T, TH> DatabaseSetDictionaryHashed<T, TH> simple(LLDictionary dictionary,
Serializer<T, ByteBuf> keySerializer,
2021-04-12 17:09:55 +02:00
Function<T, TH> keyHashFunction,
SerializerFixedBinaryLength<TH, ByteBuf> keyHashSerializer) {
2021-04-12 17:09:55 +02:00
return new DatabaseSetDictionaryHashed<>(dictionary,
2021-05-03 21:41:51 +02:00
dictionary.getAllocator().buffer(0),
2021-04-12 17:09:55 +02:00
keySerializer,
keyHashFunction,
keyHashSerializer
);
}
public static <T, TH> DatabaseSetDictionaryHashed<T, TH> tail(LLDictionary dictionary,
ByteBuf prefixKey,
Serializer<T, ByteBuf> keySuffixSerializer,
2021-04-12 17:09:55 +02:00
Function<T, TH> keyHashFunction,
SerializerFixedBinaryLength<TH, ByteBuf> 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);
}
}