Skip to main content

HashmapDatabase

Struct HashmapDatabase 

Source
pub struct HashmapDatabase<K: Eq + Hash, V> { /* private fields */ }
Expand description

The HMapDatabase mimics the behaviour of LMDBDatabase without keeping a persistent copy of the key-value records. It allows key-value pairs to be inserted, retrieved and removed in a thread-safe manner.

Implementations§

Source§

impl<K: Clone + Eq + Hash, V: Clone> HashmapDatabase<K, V>

Source

pub fn new() -> Self

Creates a new empty HMapDatabase with the specified name

Source

pub fn insert(&self, key: K, value: V) -> Result<(), KeyValStoreError>

Inserts a key-value record into the database. Internally, insert serializes the key and value using bincode and adds the pair into HashMap guarded with a RwLock.

Source

pub fn get(&self, key: &K) -> Result<Option<V>, KeyValStoreError>

Get a value from the key-value database. The retrieved value is deserialized from bincode into V

Source

pub fn is_empty(&self) -> Result<bool, KeyValStoreError>

Returns if the key-value database is empty

Source

pub fn len(&self) -> Result<usize, KeyValStoreError>

Returns the total number of entries recorded in the key-value database.

Source

pub fn for_each<F>(&self, f: F) -> Result<(), KeyValStoreError>

Iterate over all the stored records and execute the function f for each pair in the key-value database.

Source

pub fn contains_key(&self, key: &K) -> Result<bool, KeyValStoreError>

Checks whether a record exist in the key-value database that corresponds to the provided key.

Source

pub fn remove(&self, key: &K) -> Result<(), KeyValStoreError>

Remove the record from the key-value database that corresponds with the provided key.

Trait Implementations§

Source§

impl<K: Default + Eq + Hash, V: Default> Default for HashmapDatabase<K, V>

Source§

fn default() -> HashmapDatabase<K, V>

Returns the “default value” for a type. Read more
Source§

impl<K: Clone + Eq + Hash, V: Clone> KeyValueStore<K, V> for HashmapDatabase<K, V>

Source§

fn insert(&self, key: K, value: V) -> Result<(), KeyValStoreError>

Inserts a key-value pair into the key-value database.

Source§

fn get(&self, key: &K) -> Result<Option<V>, KeyValStoreError>

Get the value corresponding to the provided key from the key-value database.

Source§

fn get_many(&self, keys: &[K]) -> Result<Vec<V>, KeyValStoreError>

Get the values corresponding to the provided keys from the key-value database.

Source§

fn size(&self) -> Result<usize, KeyValStoreError>

Returns the total number of entries recorded in the key-value database.

Source§

fn for_each<F>(&self, f: F) -> Result<(), KeyValStoreError>

Iterate over all the stored records and execute the function f for each pair in the key-value database.

Source§

fn exists(&self, key: &K) -> Result<bool, KeyValStoreError>

Checks whether a record exist in the key-value database that corresponds to the provided key.

Source§

fn delete(&self, key: &K) -> Result<(), KeyValStoreError>

Remove the record from the key-value database that corresponds with the provided key.

Source§

fn for_each_ok<F>(&self, f: F) -> Result<(), KeyValStoreError>
where Self: Sized, F: FnMut((K, V)) -> IterationResult,

Execute function f for each value in the database. Any errors are filtered out. This is useful for any caller which could not do any better with an error than filtering it out. Read more
Source§

fn filter<F>(&self, predicate: F) -> Result<Vec<(K, V)>, KeyValStoreError>
where Self: Sized, F: FnMut(&(K, V)) -> bool,

Return a Vec<(K, V)> filtered by the predicate. Read more
Source§

fn filter_take<F>( &self, n: usize, predicate: F, ) -> Result<Vec<(K, V)>, KeyValStoreError>
where Self: Sized, F: FnMut(&(K, V)) -> bool,

Return a Vec<(K, V)> filtered by the predicate. At most n pairs are returned.

Auto Trait Implementations§

§

impl<K, V> !Freeze for HashmapDatabase<K, V>

§

impl<K, V> RefUnwindSafe for HashmapDatabase<K, V>

§

impl<K, V> Send for HashmapDatabase<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for HashmapDatabase<K, V>
where K: Send + Sync, V: Send + Sync,

§

impl<K, V> Unpin for HashmapDatabase<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnsafeUnpin for HashmapDatabase<K, V>

§

impl<K, V> UnwindSafe for HashmapDatabase<K, V>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> SafeBorrow<T> for T
where T: ?Sized,

Source§

fn borrow_replacement(ptr: &T) -> &T

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. 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.