Struct SortedMap
pub(super) struct SortedMap<K, V> {
entries: Vec<(K, V)>,
}alloc only.Expand description
A map kept as a Vec sorted by key.
Unlike BTreeMap, it can report a failed allocation instead of panicking.
Removing entries never allocates.
Fields§
§entries: Vec<(K, V)>Implementations§
§impl<K: Ord + Copy, V> SortedMap<K, V>
impl<K: Ord + Copy, V> SortedMap<K, V>
pub(super) const fn new() -> Self
pub(super) fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub(super) fn contains_key(&self, key: &K) -> bool
pub(super) fn try_reserve(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub(super) fn try_reserve( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Makes room for additional more entries.
pub(super) fn try_insert(
&mut self,
key: K,
value: V,
) -> Result<Option<V>, TryReserveError>
pub(super) fn try_insert( &mut self, key: K, value: V, ) -> Result<Option<V>, TryReserveError>
Sets the value for key and returns the replaced value.
The map is unchanged if the allocation fails.
pub(super) fn insert_reserved(&mut self, key: K, value: V)
pub(super) fn insert_reserved(&mut self, key: K, value: V)
Sets the value for key in room reserved earlier with
try_reserve, so it does not allocate.
pub(super) const fn len(&self) -> usize
pub(super) fn remove(&mut self, key: &K) -> Option<V>
pub(super) fn clear(&mut self)
pub(super) fn rebuild(&mut self, entries: impl Iterator<Item = (K, V)>)
pub(super) fn rebuild(&mut self, entries: impl Iterator<Item = (K, V)>)
Replaces the entries with entries, which must have unique keys and
fit in the reserved room. It does not allocate.
pub(super) fn iter(&self) -> impl Iterator<Item = (&K, &V)>
pub(super) fn keys(&self) -> impl Iterator<Item = &K>
pub(super) fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
pub(super) fn iter_from(&self, start: &K) -> impl Iterator<Item = (&K, &V)>
pub(super) fn iter_from(&self, start: &K) -> impl Iterator<Item = (&K, &V)>
Iterates the entries with keys from start on, in key order.
pub(super) fn range(
&self,
range: RangeInclusive<K>,
) -> impl Iterator<Item = (&K, &V)>
pub(super) fn range( &self, range: RangeInclusive<K>, ) -> impl Iterator<Item = (&K, &V)>
Iterates the entries with keys in range, in key order.
pub(super) fn walk(&mut self, visit: impl FnMut(&K, &mut V) -> Walk)
pub(super) fn walk(&mut self, visit: impl FnMut(&K, &mut V) -> Walk)
Visits the entries in key order and applies what visit returns.
pub(super) fn walk_range(
&mut self,
range: RangeInclusive<K>,
visit: impl FnMut(&K, &mut V) -> Walk,
)
pub(super) fn walk_range( &mut self, range: RangeInclusive<K>, visit: impl FnMut(&K, &mut V) -> Walk, )
Visits the entries with keys in range, in key order, and applies
what visit returns.
fn walk_from(
&mut self,
pos: usize,
count: usize,
visit: impl FnMut(&K, &mut V) -> Walk,
)
fn walk_from( &mut self, pos: usize, count: usize, visit: impl FnMut(&K, &mut V) -> Walk, )
Visits up to count entries from position pos on.
fn search(&self, key: &K) -> Result<usize, usize>
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for SortedMap<K, V>
impl<K, V> RefUnwindSafe for SortedMap<K, V>
impl<K, V> Send for SortedMap<K, V>
impl<K, V> Sync for SortedMap<K, V>
impl<K, V> Unpin for SortedMap<K, V>
impl<K, V> UnsafeUnpin for SortedMap<K, V>
impl<K, V> UnwindSafe for SortedMap<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more