pub struct MapRef<'a, K: Key, V> { /* private fields */ }Expand description
A convenience handle that bundles a map reference with an epoch guard.
All operations on MapRef are forwarded to the underlying LearnedMap
using the guard owned by this handle. This avoids passing a guard to
every method call.
§Example
use scry_index::LearnedMap;
let map = LearnedMap::new();
let m = map.pin();
m.insert(1u64, "hello");
assert_eq!(m.get(&1), Some(&"hello"));Implementations§
Source§impl<K: Key, V: Clone + Send + Sync> MapRef<'_, K, V>
impl<K: Key, V: Clone + Send + Sync> MapRef<'_, K, V>
Sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Look up a key, returning a reference to the value if found.
Sourcepub fn insert(&self, key: K, value: V) -> bool
pub fn insert(&self, key: K, value: V) -> bool
Insert a key-value pair. Returns true if the key was newly inserted.
Sourcepub fn remove(&self, key: &K) -> bool
pub fn remove(&self, key: &K) -> bool
Remove a key. Returns true if the key was present and removed.
Sourcepub fn get_or_insert(&self, key: K, value: V) -> &V
pub fn get_or_insert(&self, key: K, value: V) -> &V
Atomically get an existing value or insert a new one.
See LearnedMap::get_or_insert for details.
Sourcepub fn get_or_insert_with(&self, key: K, f: impl FnOnce() -> V) -> &V
pub fn get_or_insert_with(&self, key: K, f: impl FnOnce() -> V) -> &V
Atomically get an existing value or insert a computed one.
See LearnedMap::get_or_insert_with for details.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Check whether the map contains a key.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the approximate number of key-value pairs in the map.
See LearnedMap::len for details on relaxed-atomic staleness
under concurrency.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true if the map contains no entries.
Subject to the same relaxed-atomic staleness as len.
Sourcepub fn iter_sorted(&self) -> Vec<(K, V)>
pub fn iter_sorted(&self) -> Vec<(K, V)>
Collect all key-value pairs in sorted order (cloned).
Sourcepub fn range<R: RangeBounds<K>>(&self, range: R) -> Range<'_, K, V> ⓘ
pub fn range<R: RangeBounds<K>>(&self, range: R) -> Range<'_, K, V> ⓘ
Return an iterator over key-value pairs within the given range.
Sourcepub fn first_key_value(&self) -> Option<(&K, &V)>
pub fn first_key_value(&self) -> Option<(&K, &V)>
Return the first (minimum) key-value pair.
Sourcepub fn last_key_value(&self) -> Option<(&K, &V)>
pub fn last_key_value(&self) -> Option<(&K, &V)>
Return the last (maximum) key-value pair.
Sourcepub fn range_count<R: RangeBounds<K>>(&self, range: R) -> usize
pub fn range_count<R: RangeBounds<K>>(&self, range: R) -> usize
Count the number of entries within the given range.
Sourcepub fn allocated_bytes(&self) -> usize
pub fn allocated_bytes(&self) -> usize
Estimate the total heap memory allocated by this map, in bytes.
See LearnedMap::allocated_bytes for details.