pub struct KVStore<Key, T>where
T: FheIntegerType,{ /* private fields */ }Expand description
The KVStore is a specialized encrypted HashMap
- Keys are clear numbers
- Values are FheInt or FheUint
This store allows inserting, removing, and getting values using clear keys. It also allows to do some operations using encrypted keys.
To serialize a KVStore it must first be compressed with KVStore::compress
§Tag System
Ciphertexts inserted into the KVStore will drop their tag. Operations on the KVStore that return a ciphertext will set a tag using the currently set server key. Even operations that do not require FHE operations will require a server key to be set in order to set the tag
Implementations§
Source§impl<Key, T> KVStore<Key, T>where
T: FheIntegerType,
impl<Key, T> KVStore<Key, T>where
T: FheIntegerType,
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty KVStore.
Defaults to the CPU variant when no server key is set.
Sourcepub fn insert_with_clear_key(&mut self, key: Key, value: T) -> Option<T>where
Key: Ord,
pub fn insert_with_clear_key(&mut self, key: Key, value: T) -> Option<T>where
Key: Ord,
Inserts a key-value pair.
Returns the old value if there was any
Sourcepub fn update_with_clear_key(&mut self, key: &Key, value: T) -> Option<T>where
Key: Ord,
pub fn update_with_clear_key(&mut self, key: &Key, value: T) -> Option<T>where
Key: Ord,
Updates the value in a key-value pair.
Returns the old value if there was any Returns None if the key had no previous value
If your key is encrypted see Self::update
§Note
Contraty to Self::insert_with_clear_key, this does not insert the key,value pair if its not present
Sourcepub fn remove_with_clear_key(&mut self, key: &Key) -> Option<T>where
Key: Ord,
pub fn remove_with_clear_key(&mut self, key: &Key) -> Option<T>where
Key: Ord,
Removes a key-value pair.
Returns Some(_) if the key was present, None otherwise
§Note
Even though no FHE computations are done, a server key must be set when calling this function is order to set the Tag of the resulting ciphertext
Sourcepub fn contains_clear_key(&self, key: &Key) -> boolwhere
Key: Ord,
pub fn contains_clear_key(&self, key: &Key) -> boolwhere
Key: Ord,
Returns true if the store contains a value for the given clear key.
If your key is encrypted see Self::contains_key
Sourcepub fn get_with_clear_key(&self, key: &Key) -> Option<T>where
Key: Ord,
pub fn get_with_clear_key(&self, key: &Key) -> Option<T>where
Key: Ord,
Source§impl<Key, T> KVStore<Key, T>
impl<Key, T> KVStore<Key, T>
Sourcepub fn get<EK>(&self, encrypted_key: &EK) -> (T, FheBool)
pub fn get<EK>(&self, encrypted_key: &EK) -> (T, FheBool)
Gets the value corresponding to the encrypted key.
Returns the encrypted value and an encrypted boolean. The boolean is an encryption of true if the key was present, thus the value is meaningful.
If your key is clear see Self::get_with_clear_key
Sourcepub fn contains_key<EK>(&self, encrypted_key: &EK) -> FheBool
pub fn contains_key<EK>(&self, encrypted_key: &EK) -> FheBool
Checks if the store contains a value for the given encrypted key.
Returns an encrypted boolean that encrypts true if the key was found.
If your key is clear see Self::contains_clear_key
Sourcepub fn contains_value(&self, encrypted_value: &T) -> FheBool
pub fn contains_value(&self, encrypted_value: &T) -> FheBool
Checks if the store contains the given encrypted value.
Returns an encrypted boolean that encrypts true if the value was found.
Sourcepub fn contains_clear_value<Clear>(&self, clear_value: Clear) -> FheBoolwhere
Clear: DecomposableInto<u64>,
pub fn contains_clear_value<Clear>(&self, clear_value: Clear) -> FheBoolwhere
Clear: DecomposableInto<u64>,
Checks if the store contains the given clear value.
Returns an encrypted boolean that encrypts true if the value was found.
Sourcepub fn update<EK>(&mut self, encrypted_key: &EK, new_value: &T) -> FheBool
pub fn update<EK>(&mut self, encrypted_key: &EK, new_value: &T) -> FheBool
Replaces the value corresponding to the encrypted key.
i.e. kvstore[encrypted_value] = new_value
The boolean is an encryption of true if the key was present, thus the value is was replaced.
If your key is clear see Self::update_with_clear_key
Sourcepub fn map<EK, F>(&mut self, encrypted_key: &EK, func: F) -> (T, T, FheBool)
pub fn map<EK, F>(&mut self, encrypted_key: &EK, func: F) -> (T, T, FheBool)
Replaces the value corresponding to the encrypted key, with the result of applying the function to the current value.
i.e. kvstore[encrypted_value] = func(kvstore[encrypted_value])
Returns (old_value, new_value, check)
The check boolean is an encryption of true if the key was present,
thus the value is was replaced.
Trait Implementations§
Auto Trait Implementations§
impl<Key, T> Freeze for KVStore<Key, T>
impl<Key, T> RefUnwindSafe for KVStore<Key, T>where
Key: RefUnwindSafe,
<<T as FheIntegerType>::Id as IntegerId>::InnerCpu: RefUnwindSafe,
<<T as FheIntegerType>::Id as IntegerId>::InnerGpu: RefUnwindSafe,
impl<Key, T> Send for KVStore<Key, T>where
Key: Send,
impl<Key, T> Sync for KVStore<Key, T>
impl<Key, T> Unpin for KVStore<Key, T>
impl<Key, T> UnsafeUnpin for KVStore<Key, T>
impl<Key, T> UnwindSafe for KVStore<Key, T>where
Key: RefUnwindSafe,
<<T as FheIntegerType>::Id as IntegerId>::InnerCpu: RefUnwindSafe,
<<T as FheIntegerType>::Id as IntegerId>::InnerGpu: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more