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>
impl<K: Clone + Eq + Hash, V: Clone> HashmapDatabase<K, V>
Sourcepub fn insert(&self, key: K, value: V) -> Result<(), KeyValStoreError>
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.
Sourcepub fn get(&self, key: &K) -> Result<Option<V>, KeyValStoreError>
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
Sourcepub fn is_empty(&self) -> Result<bool, KeyValStoreError>
pub fn is_empty(&self) -> Result<bool, KeyValStoreError>
Returns if the key-value database is empty
Sourcepub fn len(&self) -> Result<usize, KeyValStoreError>
pub fn len(&self) -> Result<usize, KeyValStoreError>
Returns the total number of entries recorded in the key-value database.
Sourcepub fn for_each<F>(&self, f: F) -> Result<(), KeyValStoreError>
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.
Sourcepub fn contains_key(&self, key: &K) -> Result<bool, KeyValStoreError>
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.
Trait Implementations§
Source§impl<K: Default + Eq + Hash, V: Default> Default for HashmapDatabase<K, V>
impl<K: Default + Eq + Hash, V: Default> Default for HashmapDatabase<K, V>
Source§fn default() -> HashmapDatabase<K, V>
fn default() -> HashmapDatabase<K, V>
Source§impl<K: Clone + Eq + Hash, V: Clone> KeyValueStore<K, V> for HashmapDatabase<K, V>
impl<K: Clone + Eq + Hash, V: Clone> KeyValueStore<K, V> for HashmapDatabase<K, V>
Source§fn insert(&self, key: K, value: V) -> Result<(), KeyValStoreError>
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>
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>
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>
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>
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>
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>
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>
fn for_each_ok<F>(&self, f: F) -> Result<(), KeyValStoreError>
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