ArrayMap

Struct ArrayMap 

Source
pub struct ArrayMap<K, V, const N: usize>
where K: PartialEq + Default, V: Default,
{ /* private fields */ }
Expand description

A generic tinyvec::ArrayVec backed map with O(n) lookup. Maintains insertion order and tracks the last updated entry index.

Implementations§

Source§

impl<K, V, const N: usize> ArrayMap<K, V, N>
where K: PartialEq + Default, V: Default,

Source

pub fn new() -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn last_updated_index(&self) -> Option<usize>

Source

pub fn get_by_index(&self, index: usize) -> Option<&(K, V)>

Source

pub fn get_by_index_mut(&mut self, index: usize) -> Option<&mut (K, V)>

Source

pub fn get_by_index_u8(&self, index: u8) -> Option<&(K, V)>

Source

pub fn get_by_index_mut_u8(&mut self, index: u8) -> Option<&mut (K, V)>

Source

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

Source

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

Source

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

Source

pub fn find_mut(&mut self, key: &K) -> Option<(usize, &mut (K, V))>

Source

pub fn find_index(&self, key: &K) -> Option<usize>

Source

pub fn set_last_updated_index<E>(&mut self, index: usize) -> Result<(), E>
where E: From<ArrayMapError>,

Source

pub fn insert<E>(&mut self, key: K, value: V, error: E) -> Result<usize, E>

Source§

impl<V, const N: usize> ArrayMap<[u8; 32], V, N>
where V: Default,

Source

pub fn get_by_pubkey(&self, key: &[u8; 32]) -> Option<&V>

Source

pub fn get_mut_by_pubkey(&mut self, key: &[u8; 32]) -> Option<&mut V>

Source

pub fn find_by_pubkey(&self, key: &[u8; 32]) -> Option<(usize, &([u8; 32], V))>

Source

pub fn find_mut_by_pubkey( &mut self, key: &[u8; 32], ) -> Option<(usize, &mut ([u8; 32], V))>

Source

pub fn find_pubkey_index(&self, key: &[u8; 32]) -> Option<usize>

Trait Implementations§

Source§

impl<K, V, const N: usize> Default for ArrayMap<K, V, N>
where K: PartialEq + Default, V: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V, const N: usize> Freeze for ArrayMap<K, V, N>
where K: Freeze, V: Freeze,

§

impl<K, V, const N: usize> RefUnwindSafe for ArrayMap<K, V, N>

§

impl<K, V, const N: usize> Send for ArrayMap<K, V, N>
where K: Send, V: Send,

§

impl<K, V, const N: usize> Sync for ArrayMap<K, V, N>
where K: Sync, V: Sync,

§

impl<K, V, const N: usize> Unpin for ArrayMap<K, V, N>
where K: Unpin, V: Unpin,

§

impl<K, V, const N: usize> UnwindSafe for ArrayMap<K, V, N>
where K: UnwindSafe, V: UnwindSafe,

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, 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.