Skip to main content

Unordered

Trait Unordered 

Source
pub trait Unordered: Send + Sync {
    type Value: Send + Sync;
    type Cursor<'a>: Cursor<Value = Self::Value>
       where Self: 'a;

    // Required methods
    fn get<'a>(
        &'a self,
        key: &[u8],
    ) -> impl Iterator<Item = &'a Self::Value> + Send + 'a
       where Self::Value: 'a;
    fn get_mut<'a>(&'a mut self, key: &[u8]) -> Option<Self::Cursor<'a>>;
    fn get_mut_or_insert<'a>(
        &'a mut self,
        key: &[u8],
        value: Self::Value,
    ) -> Option<Self::Cursor<'a>>;
    fn insert(&mut self, key: &[u8], value: Self::Value);
    fn insert_and_retain(
        &mut self,
        key: &[u8],
        value: Self::Value,
        should_retain: impl Fn(&Self::Value) -> bool,
    );
    fn remove(&mut self, key: &[u8]);

    // Provided method
    fn retain(
        &mut self,
        key: &[u8],
        should_retain: impl Fn(&Self::Value) -> bool,
    ) { ... }
}
Expand description

A trait defining the operations provided by a memory-efficient index that maps translated keys to arbitrary values, with no ordering assumed over the key space.

Required Associated Types§

Source

type Value: Send + Sync

The type of values the index stores.

Source

type Cursor<'a>: Cursor<Value = Self::Value> where Self: 'a

The type of cursor returned by this index to iterate over values with conflicting keys.

Required Methods§

Source

fn get<'a>( &'a self, key: &[u8], ) -> impl Iterator<Item = &'a Self::Value> + Send + 'a
where Self::Value: 'a,

Returns an iterator over all values associated with a translated key.

Source

fn get_mut<'a>(&'a mut self, key: &[u8]) -> Option<Self::Cursor<'a>>

Provides mutable access to the values associated with a translated key, if the key exists.

Source

fn get_mut_or_insert<'a>( &'a mut self, key: &[u8], value: Self::Value, ) -> Option<Self::Cursor<'a>>

Provides mutable access to the values associated with a translated key (if the key exists), otherwise inserts a new value and returns None.

Source

fn insert(&mut self, key: &[u8], value: Self::Value)

Inserts a new value for the translated key.

Source

fn insert_and_retain( &mut self, key: &[u8], value: Self::Value, should_retain: impl Fn(&Self::Value) -> bool, )

Insert a value at the given translated key, and remove any values for which should_retain returns false.

If should_retain returns false for the new value, it will not be inserted.

Source

fn remove(&mut self, key: &[u8])

Remove all values associated with a translated key.

Provided Methods§

Source

fn retain(&mut self, key: &[u8], should_retain: impl Fn(&Self::Value) -> bool)

Retain only the values associated with a translated key for which should_retain returns true. All other values are removed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Translator, V: Send + Sync> Unordered for commonware_storage::index::ordered::Index<T, V>

Source§

type Value = V

Source§

type Cursor<'a> = Cursor<'a, V, OccupiedEntry<'a, <T as Translator>::Key, Record<V>>> where Self: 'a

Source§

impl<T: Translator, V: Send + Sync> Unordered for commonware_storage::index::unordered::Index<T, V>

Source§

type Value = V

Source§

type Cursor<'a> = Cursor<'a, V, OccupiedEntry<'a, <T as Translator>::Key, Record<V>>> where Self: 'a

Source§

impl<T: Translator, V: Send + Sync, const P: usize> Unordered for commonware_storage::index::partitioned::ordered::Index<T, V, P>

Source§

type Value = V

Source§

type Cursor<'a> = <Index<T, V> as Unordered>::Cursor<'a> where Self: 'a

Source§

impl<T: Translator, V: Send + Sync, const P: usize> Unordered for commonware_storage::index::partitioned::unordered::Index<T, V, P>

Source§

type Value = V

Source§

type Cursor<'a> = <Index<T, V> as Unordered>::Cursor<'a> where Self: 'a