pub struct SortedArray<K, V, const N: usize> { /* private fields */ }
Expand description
A constant-size, zero-allocation associative container based on a sorted array.
Implementations§
Source§impl<K, V, const N: usize> SortedArray<K, V, N>
impl<K, V, const N: usize> SortedArray<K, V, N>
Sourcepub fn get_exact(&self, key: &K) -> Option<&V>where
K: Ord,
pub fn get_exact(&self, key: &K) -> Option<&V>where
K: Ord,
Return an entry which is an exact match for the key
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: Ord,
pub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: Ord,
Inserts an item and return the previous value if it exists.
§Panics
This method will panic if called with a new key-value pair when already full.
The SortedArray
should be checked to ensure that it is not already
full before calling this method. It is full when the self.is_full()
method returns true
, which happens when self.len() == N
.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>where
K: Ord,
pub fn remove(&mut self, key: &K) -> Option<V>where
K: Ord,
Remove an element from the sorted array
Sourcepub fn contains_key(&self, key: &K) -> boolwhere
K: Ord,
pub fn contains_key(&self, key: &K) -> boolwhere
K: Ord,
Check if the array contains a given element.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = &SortedArrayEntry<K, V>>
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &SortedArrayEntry<K, V>>
A double ended iterator through the entries of the array.
Sourcepub fn split_off(&mut self, split_idx: usize) -> Self
pub fn split_off(&mut self, split_idx: usize) -> Self
Splits this SortedArray
into two. self
will retain
all key-value pairs before the provided split index.
Returns a new SortedArray
created out of all key-value pairs
at or after the provided split index.
Sourcepub fn get_lower_bound(&self, key: &K) -> Option<&V>where
K: Ord,
pub fn get_lower_bound(&self, key: &K) -> Option<&V>where
K: Ord,
Get the key-value pair that is less than or equal to the provided key.
Sourcepub fn get_lower_bound_always(&self, key: &K) -> &Vwhere
K: Ord,
pub fn get_lower_bound_always(&self, key: &K) -> &Vwhere
K: Ord,
Get the key-value pair that is less than or equal to the provided key, or the first key-value pair.
Source§impl<K, V, const N: usize> SortedArray<K, V, N>
impl<K, V, const N: usize> SortedArray<K, V, N>
Sourcepub fn entries(&self) -> &[SortedArrayEntry<K, V>]
pub fn entries(&self) -> &[SortedArrayEntry<K, V>]
Borrow a slice view into the entries stored in the SortedArray
Sourcepub fn get_index(&self, index: usize) -> Option<&SortedArrayEntry<K, V>>
pub fn get_index(&self, index: usize) -> Option<&SortedArrayEntry<K, V>>
Get a key-value pair based on its internal relative index in the backing array.
Sourcepub fn first(&self) -> Option<&SortedArrayEntry<K, V>>
pub fn first(&self) -> Option<&SortedArrayEntry<K, V>>
Returns the first key-value pair in the array, if any exists.
Sourcepub fn last(&self) -> Option<&SortedArrayEntry<K, V>>
pub fn last(&self) -> Option<&SortedArrayEntry<K, V>>
Returns the last key-value pair in the array, if any exists.