Struct SortedArray

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

Source

pub fn empty() -> Self

Create an empty sorted array

Source

pub fn get_exact(&self, key: &K) -> Option<&V>
where K: Ord,

Return an entry which is an exact match for the key

Source

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.

Source

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

Remove an element from the sorted array

Source

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

Check if the array contains a given element.

Source

pub fn iter(&self) -> impl DoubleEndedIterator<Item = &SortedArrayEntry<K, V>>

A double ended iterator through the entries of the array.

Source

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.

Source

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.

Source

pub fn get_lower_bound_always(&self, key: &K) -> &V
where 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>

Source

pub fn entries(&self) -> &[SortedArrayEntry<K, V>]

Borrow a slice view into the entries stored in the SortedArray

Source

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.

Source

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

Returns the first key-value pair in the array, if any exists.

Source

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

Returns the last key-value pair in the array, if any exists.

Source

pub fn is_full(&self) -> bool

Returns whether this array is at its maximum capacity and unable to receive additional data.

Source

pub fn len(&self) -> usize

Returns the number of elements in the array.

Source

pub fn is_empty(&self) -> bool

Returns whether the array has any elements.

Trait Implementations§

Source§

impl<K: Clone, V: Clone, const N: usize> Clone for SortedArray<K, V, N>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, V: Debug, const N: usize> Debug for SortedArray<K, V, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V, const N: usize> Default for SortedArray<K, V, N>

Source§

fn default() -> Self

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

impl<K, V, const N: usize> PartialEq for SortedArray<K, V, N>
where K: PartialEq, V: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, V, const N: usize> Eq for SortedArray<K, V, N>
where K: PartialEq, V: PartialEq,

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<K, V, const N: usize> UnwindSafe for SortedArray<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.