PopulatedBTreeMap

Struct PopulatedBTreeMap 

Source
pub struct PopulatedBTreeMap<K, V>(/* private fields */);
Expand description

An ordered map based on a B-Tree that is guaranteed to have at least one key-value pair.

Implementations§

Source§

impl<K: Ord, V> PopulatedBTreeMap<K, V>

Source

pub fn new(key: K, value: V) -> PopulatedBTreeMap<K, V>

Makes a new PopulatedBTreeMap with a single key-value pair.

Source

pub fn get<Q: Ord + ?Sized>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>,

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Source

pub fn get_key_value<Q: Ord + ?Sized>(&self, k: &Q) -> Option<(&K, &V)>
where K: Borrow<Q>,

Returns the key-value pair corresponding to the supplied key.

The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Source

pub fn first_key_value(&self) -> (&K, &V)

Returns the first key-value pair in the map. The key in this pair is the minimum key in the map.

Source

pub fn pop_first(self) -> ((K, V), BTreeMap<K, V>)

Removes and returns the first element in the map. The key of this element is the minimum key that was in the map.

Source

pub fn last_key_value(&self) -> (&K, &V)

Returns the last key-value pair in the map. The key in this pair is the maximum key in the map.

Source

pub fn pop_last(self) -> (BTreeMap<K, V>, (K, V))

Removes and returns the last element in the map. The key of this element is the maximum key that was in the map.

Source

pub fn contains_key<Q: Ord + ?Sized>(&self, k: &Q) -> bool
where K: Borrow<Q>,

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Source

pub fn get_mut<Q: Ord + ?Sized>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>,

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Source

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

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical. See the module-level documentation for more.

Source

pub fn remove<Q: Ord + ?Sized>( self, k: &Q, ) -> Result<(V, BTreeMap<K, V>), PopulatedBTreeMap<K, V>>
where K: Borrow<Q>,

Removes a key from the map, returning the value at the key if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Source

pub fn remove_entry<Q: Ord + ?Sized>(self, k: &Q) -> EntryRemovalResult<K, V>
where K: Borrow<Q>,

Removes a key from the map, returning the stored key and value if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

Source

pub fn retain(self, predicate: impl FnMut(&K, &mut V) -> bool) -> BTreeMap<K, V>

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) for which f(&k, &mut v) returns false. The elements are visited in ascending key order.

Source

pub fn append(&mut self, other: &mut BTreeMap<K, V>)

Moves all elements from other into self, leaving other empty.

If a key from other is already present in self, the respective value from self will be overwritten with the respective value from other.

Source

pub fn range<T: Ord + ?Sized>( &self, range: impl RangeBounds<T>, ) -> Range<'_, K, V>
where K: Borrow<T>,

Constructs a double-ended iterator over a sub-range of elements in the map. The simplest way is to use the range syntax min..max, thus range(min..max) will yield elements from min (inclusive) to max (exclusive). The range may also be entered as (Bound<T>, Bound<T>), so for example range((Excluded(4), Included(10))) will yield a left-exclusive, right-inclusive range from 4 to 10.

Source

pub fn split_at<Q: Ord + ?Sized>( self, key: &Q, ) -> (BTreeMap<K, V>, BTreeMap<K, V>)
where K: Borrow<Q>,

Source§

impl<K, V> PopulatedBTreeMap<K, V>

Source

pub fn clear(self) -> BTreeMap<K, V>

Source

pub fn len(&self) -> NonZeroUsize

Returns the number of elements in the map.

Source§

impl<K, V> PopulatedBTreeMap<K, V>

Source

pub fn iter(&self) -> PopulatedIter<'_, K, V>

Source

pub fn iter_mut(&mut self) -> PopulatedIterMut<'_, K, V>

Source

pub fn keys(&self) -> PopulatedKeys<'_, K, V>

Source

pub fn values(&self) -> PopulatedValues<'_, K, V>

Source

pub fn values_mut(&mut self) -> PopulatedValuesMut<'_, K, V>

Source

pub fn into_keys(self) -> PopulatedIntoKeys<K, V>

Source

pub fn into_values(self) -> PopulatedIntoValues<K, V>

Trait Implementations§

Source§

impl<K: Clone, V: Clone> Clone for PopulatedBTreeMap<K, V>

Source§

fn clone(&self) -> PopulatedBTreeMap<K, V>

Returns a duplicate 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> Debug for PopulatedBTreeMap<K, V>

Source§

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

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

impl<K, V> From<PopulatedBTreeMap<K, V>> for BTreeMap<K, V>

Source§

fn from(populated_btree_map: PopulatedBTreeMap<K, V>) -> BTreeMap<K, V>

Converts to this type from the input type.
Source§

impl<K: Ord, V> FromPopulatedIterator<(K, V)> for PopulatedBTreeMap<K, V>

Source§

fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = (K, V)>) -> Self

Converts a PopulatedIterator into Self.
Source§

impl<K, V> Index<&K> for PopulatedBTreeMap<K, V>
where K: Ord,

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, key: &K) -> &V

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, K, V> IntoIterator for &'a PopulatedBTreeMap<K, V>

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, K, V> IntoIterator for &'a mut PopulatedBTreeMap<K, V>

Source§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, V> IntoIterator for PopulatedBTreeMap<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, K, V> IntoPopulatedIterator for &'a PopulatedBTreeMap<K, V>

Source§

type PopulatedIntoIter = PopulatedIter<'a, K, V>

Source§

fn into_populated_iter(self) -> PopulatedIter<'a, K, V>

Converts the type into a PopulatedIterator.
Source§

impl<'a, K, V> IntoPopulatedIterator for &'a mut PopulatedBTreeMap<K, V>

Source§

type PopulatedIntoIter = PopulatedIterMut<'a, K, V>

Source§

fn into_populated_iter(self) -> PopulatedIterMut<'a, K, V>

Converts the type into a PopulatedIterator.
Source§

impl<K, V> IntoPopulatedIterator for PopulatedBTreeMap<K, V>

Source§

type PopulatedIntoIter = IntoPopulatedIter<K, V>

Source§

fn into_populated_iter(self) -> IntoPopulatedIter<K, V>

Converts the type into a PopulatedIterator.
Source§

impl<K: Ord, V: Ord> Ord for PopulatedBTreeMap<K, V>

Source§

fn cmp(&self, other: &PopulatedBTreeMap<K, V>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<K: PartialEq, V: PartialEq> PartialEq for PopulatedBTreeMap<K, V>

Source§

fn eq(&self, other: &PopulatedBTreeMap<K, V>) -> 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: PartialOrd, V: PartialOrd> PartialOrd for PopulatedBTreeMap<K, V>

Source§

fn partial_cmp(&self, other: &PopulatedBTreeMap<K, V>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<K, V> TryFrom<BTreeMap<K, V>> for PopulatedBTreeMap<K, V>

Source§

type Error = BTreeMap<K, V>

The type returned in the event of a conversion error.
Source§

fn try_from( btree_map: BTreeMap<K, V>, ) -> Result<PopulatedBTreeMap<K, V>, Self::Error>

Performs the conversion.
Source§

impl<K: Eq, V: Eq> Eq for PopulatedBTreeMap<K, V>

Source§

impl<K, V> StructuralPartialEq for PopulatedBTreeMap<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for PopulatedBTreeMap<K, V>

§

impl<K, V> RefUnwindSafe for PopulatedBTreeMap<K, V>

§

impl<K, V> Send for PopulatedBTreeMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for PopulatedBTreeMap<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for PopulatedBTreeMap<K, V>

§

impl<K, V> UnwindSafe for PopulatedBTreeMap<K, V>

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.