Skip to main content

KVStore

Struct KVStore 

Source
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,

Source

pub fn new() -> Self

Creates a new empty KVStore.

Defaults to the CPU variant when no server key is set.

Source

pub fn len(&self) -> usize

Returns the number of key-value pairs in the store.

Source

pub fn is_empty(&self) -> bool

Returns true if the store contains no key-value pairs

Source

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

Source

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

Source

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

Source

pub fn contains_clear_key(&self, key: &Key) -> bool
where Key: Ord,

Returns true if the store contains a value for the given clear key.

If your key is encrypted see Self::contains_key

Source

pub fn get_with_clear_key(&self, key: &Key) -> Option<T>
where Key: Ord,

Returns the value associated to a key.

Returns Some(_) if the key was present, None otherwise

If your key is encrypted see Self::get

§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

Source§

impl<Key, T> KVStore<Key, T>

Source

pub fn get<EK>(&self, encrypted_key: &EK) -> (T, FheBool)
where EK: FheIntegerType, EK::Id: IntegerId<InnerCpu = <T::Id as IntegerId>::InnerCpu, InnerGpu = <T::Id as IntegerId>::InnerGpu>,

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

Source

pub fn contains_key<EK>(&self, encrypted_key: &EK) -> FheBool
where EK: FheIntegerType, EK::Id: IntegerId<InnerCpu = <T::Id as IntegerId>::InnerCpu, InnerGpu = <T::Id as IntegerId>::InnerGpu>,

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

Source

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.

Source

pub fn contains_clear_value<Clear>(&self, clear_value: Clear) -> FheBool
where Clear: DecomposableInto<u64>,

Checks if the store contains the given clear value.

Returns an encrypted boolean that encrypts true if the value was found.

Source

pub fn update<EK>(&mut self, encrypted_key: &EK, new_value: &T) -> FheBool
where EK: FheIntegerType, EK::Id: IntegerId<InnerCpu = <T::Id as IntegerId>::InnerCpu, InnerGpu = <T::Id as IntegerId>::InnerGpu>,

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

Source

pub fn map<EK, F>(&mut self, encrypted_key: &EK, func: F) -> (T, T, FheBool)
where EK: FheIntegerType, EK::Id: IntegerId<InnerCpu = <T::Id as IntegerId>::InnerCpu, InnerGpu = <T::Id as IntegerId>::InnerGpu>, F: Fn(T) -> T,

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.

Source

pub fn compress(&self) -> Result<CompressedKVStore<Key, T>>
where Key: Copy + Display + Ord, <T::Id as IntegerId>::InnerCpu: Compressible + Clone,

Compressed the KVStore, making it serializable

Trait Implementations§

Source§

impl<Key, T> Clone for KVStore<Key, T>
where Key: Clone + Ord, T: FheIntegerType, <T::Id as IntegerId>::InnerCpu: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Key, T> Default for KVStore<Key, T>
where T: FheIntegerType,

Source§

fn default() -> Self

Defaults to the CPU variant when no server key is set.

Auto Trait Implementations§

§

impl<Key, T> Freeze for KVStore<Key, T>

§

impl<Key, T> RefUnwindSafe for KVStore<Key, T>

§

impl<Key, T> Send for KVStore<Key, T>
where Key: Send,

§

impl<Key, T> Sync for KVStore<Key, T>
where Key: Sync, <<T as FheIntegerType>::Id as IntegerId>::InnerGpu: Sync,

§

impl<Key, T> Unpin for KVStore<Key, T>

§

impl<Key, T> UnsafeUnpin for KVStore<Key, T>

§

impl<Key, T> UnwindSafe for KVStore<Key, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Input, Output> CastInto<Output> for Input
where Output: CastFrom<Input>,

Source§

fn cast_into(self) -> Output

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<A> SafeAs for A

Source§

fn sas<T>(self) -> T
where A: TryInto<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more