Skip to main content

MapRef

Struct MapRef 

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

Source

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

Look up a key, returning a reference to the value if found.

Source

pub fn insert(&self, key: K, value: V) -> bool

Insert a key-value pair. Returns true if the key was newly inserted.

Source

pub fn remove(&self, key: &K) -> bool

Remove a key. Returns true if the key was present and removed.

Source

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.

Source

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.

Source

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

Check whether the map contains a key.

Source

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.

Source

pub fn is_empty(&self) -> bool

Return true if the map contains no entries.

Subject to the same relaxed-atomic staleness as len.

Source

pub fn iter(&self) -> Iter<'_, K, V>

Iterate over all key-value pairs in sorted order.

Source

pub fn iter_sorted(&self) -> Vec<(K, V)>

Collect all key-value pairs in sorted order (cloned).

Source

pub fn range<R: RangeBounds<K>>(&self, range: R) -> Range<'_, K, V>

Return an iterator over key-value pairs within the given range.

Source

pub fn first_key_value(&self) -> Option<(&K, &V)>

Return the first (minimum) key-value pair.

Source

pub fn last_key_value(&self) -> Option<(&K, &V)>

Return the last (maximum) key-value pair.

Source

pub fn range_count<R: RangeBounds<K>>(&self, range: R) -> usize

Count the number of entries within the given range.

Source

pub fn allocated_bytes(&self) -> usize

Estimate the total heap memory allocated by this map, in bytes.

See LearnedMap::allocated_bytes for details.

Source

pub fn max_depth(&self) -> usize

Return the maximum depth of the tree.

Source

pub fn rebuild(&self)

Rebuild the tree from scratch using bulk load.

Source

pub fn drain(&self) -> Vec<(K, V)>

Remove all entries from the map and return them as a sorted Vec.

Source

pub fn clear(&self)

Remove all entries from the map.

Auto Trait Implementations§

§

impl<'a, K, V> Freeze for MapRef<'a, K, V>

§

impl<'a, K, V> !RefUnwindSafe for MapRef<'a, K, V>

§

impl<'a, K, V> !Send for MapRef<'a, K, V>

§

impl<'a, K, V> !Sync for MapRef<'a, K, V>

§

impl<'a, K, V> Unpin for MapRef<'a, K, V>

§

impl<'a, K, V> UnsafeUnpin for MapRef<'a, K, V>

§

impl<'a, K, V> !UnwindSafe for MapRef<'a, 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> 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<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.