pub struct Table<'txn, K: Key + 'static, V: Value + 'static> { /* private fields */ }Expand description
A table containing key-value mappings
Implementations§
Source§impl<'txn, K: Key + 'static, V: Value + 'static> Table<'txn, K, V>
impl<'txn, K: Key + 'static, V: Value + 'static> Table<'txn, K, V>
Sourcepub fn get_mut<'k>(
&mut self,
key: impl Borrow<K::SelfType<'k>>,
) -> Result<Option<AccessGuardMut<'_, V>>>
pub fn get_mut<'k>( &mut self, key: impl Borrow<K::SelfType<'k>>, ) -> Result<Option<AccessGuardMut<'_, V>>>
Returns an accessor, which allows mutation, to the value corresponding to the given key
Sourcepub fn pop_first(
&mut self,
) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>
pub fn pop_first( &mut self, ) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>
Removes and returns the first key-value pair in the table
Sourcepub fn pop_last(
&mut self,
) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>
pub fn pop_last( &mut self, ) -> Result<Option<(AccessGuard<'_, K>, AccessGuard<'_, V>)>>
Removes and returns the last key-value pair in the table
Sourcepub fn extract_if<F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>(
&mut self,
predicate: F,
) -> Result<ExtractIf<'_, K, V, F>>
pub fn extract_if<F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>( &mut self, predicate: F, ) -> Result<ExtractIf<'_, K, V, F>>
Applies predicate to all key-value pairs. All entries for which
predicate evaluates to true are returned in an iterator, and those which are read from the iterator are removed
Note: values not read from the iterator will not be removed
Sourcepub fn extract_from_if<'a, KR, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>(
&mut self,
range: impl RangeBounds<KR> + 'a,
predicate: F,
) -> Result<ExtractIf<'_, K, V, F>>
pub fn extract_from_if<'a, KR, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>( &mut self, range: impl RangeBounds<KR> + 'a, predicate: F, ) -> Result<ExtractIf<'_, K, V, F>>
Applies predicate to all key-value pairs in the specified range. All entries for which
predicate evaluates to true are returned in an iterator, and those which are read from the iterator are removed
Note: values not read from the iterator will not be removed
Sourcepub fn retain<F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>(
&mut self,
predicate: F,
) -> Result
pub fn retain<F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>( &mut self, predicate: F, ) -> Result
Applies predicate to all key-value pairs. All entries for which
predicate evaluates to false are removed.
Sourcepub fn retain_in<'a, KR, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>(
&mut self,
range: impl RangeBounds<KR> + 'a,
predicate: F,
) -> Result
pub fn retain_in<'a, KR, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool>( &mut self, range: impl RangeBounds<KR> + 'a, predicate: F, ) -> Result
Applies predicate to all key-value pairs in the range start..end. All entries for which
predicate evaluates to false are removed.
Sourcepub fn insert<'k, 'v>(
&mut self,
key: impl Borrow<K::SelfType<'k>>,
value: impl Borrow<V::SelfType<'v>>,
) -> Result<Option<AccessGuard<'_, V>>>
pub fn insert<'k, 'v>( &mut self, key: impl Borrow<K::SelfType<'k>>, value: impl Borrow<V::SelfType<'v>>, ) -> Result<Option<AccessGuard<'_, V>>>
Insert mapping of the given key to the given value
If key is already present it is replaced
Returns the old value, if the key was present in the table, otherwise None is returned
Sourcepub fn remove<'a>(
&mut self,
key: impl Borrow<K::SelfType<'a>>,
) -> Result<Option<AccessGuard<'_, V>>>
pub fn remove<'a>( &mut self, key: impl Borrow<K::SelfType<'a>>, ) -> Result<Option<AccessGuard<'_, V>>>
Removes the given key
Returns the old value, if the key was present in the table
Sourcepub fn insert_bulk<'i, I>(&mut self, items: I, sorted: bool) -> Result<usize>
pub fn insert_bulk<'i, I>(&mut self, items: I, sorted: bool) -> Result<usize>
Bulk insert optimized for loading large datasets
This method provides significant performance improvements over individual
insert() calls for bulk data loading scenarios.
§Arguments
items- Iterator of (key, value) pairs to insertsorted- Hint indicating whether items are already sorted by key. Set totrueif you know the data is sorted for optimal performance.
§Performance
- Sorted data: 2-3x faster than individual inserts (uses optimized bulk construction)
- Unsorted data: 1.5-2x faster than individual inserts (uses batched insertion with sorting)
§Returns
Returns the total number of items inserted
§Errors
Returns an error if:
- Any key or value exceeds maximum size limits
- Storage errors occur during insertion
§Examples
// Pre-sorted data (best performance)
let sorted_data = vec![(1u64, "one"), (2u64, "two"), (3u64, "three")];
let count = table.insert_bulk(sorted_data.into_iter(), true)?;
// Unsorted data (still faster than individual inserts)
let unsorted_data = vec![(10u64, "ten"), (5u64, "five"), (7u64, "seven")];
let count = table.insert_bulk(unsorted_data.into_iter(), false)?;Sourcepub fn remove_bulk<'i, I>(&mut self, keys: I) -> Result<usize>where
I: IntoIterator<Item = K::SelfType<'i>>,
pub fn remove_bulk<'i, I>(&mut self, keys: I) -> Result<usize>where
I: IntoIterator<Item = K::SelfType<'i>>,
Bulk remove optimized for deleting multiple keys
This method provides performance improvements over individual
remove() calls when deleting many keys at once.
§Arguments
keys- Iterator of keys to remove
§Returns
Returns the number of keys that were actually removed (keys that existed in the table)
§Examples
let keys_to_delete = vec![1u64, 2u64, 3u64, 4u64, 5u64];
let removed_count = table.remove_bulk(keys_to_delete.into_iter())?;Source§impl<K: Key + 'static, V: MutInPlaceValue + 'static> Table<'_, K, V>
impl<K: Key + 'static, V: MutInPlaceValue + 'static> Table<'_, K, V>
Sourcepub fn insert_reserve<'a>(
&mut self,
key: impl Borrow<K::SelfType<'a>>,
value_length: usize,
) -> Result<AccessGuardMutInPlace<'_, V>>
pub fn insert_reserve<'a>( &mut self, key: impl Borrow<K::SelfType<'a>>, value_length: usize, ) -> Result<AccessGuardMutInPlace<'_, V>>
Reserve space to insert a key-value pair
If key is already present it is replaced
The returned reference will have length equal to value_length