Struct frame_support::storage::bounded_btree_map::BoundedBTreeMap [−][src]
pub struct BoundedBTreeMap<K, V, S>(_, _);
Expand description
A bounded map based on a B-Tree.
B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
the amount of work performed in a search. See BTreeMap
for more details.
Unlike a standard BTreeMap
, there is an enforced upper limit to the number of items in the
map. All internal operations ensure this bound is respected.
Implementations
Consume self, and return the inner BTreeMap
.
This is useful when a mutating API of the inner type is desired, and closure-based mutation
such as provided by try_mutate
is inconvenient.
Consumes self and mutates self via the given mutate
function.
If the outcome of mutation is within bounds, Some(Self)
is returned. Else, None
is
returned.
This is essentially a consuming shorthand Self::into_inner
-> ...
->
Self::try_from
.
Return 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.
Exactly the same semantics as BTreeMap::insert
, but returns an Err
(and is a noop) if
the new length of the map exceeds S
.
In the Err
case, returns the inserted pair so it can be further used without cloning.
Remove 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.
Remove 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.
Methods from Deref<Target = BTreeMap<K, V>>
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.
Examples
Basic usage:
use std::collections::BTreeMap; let mut map = BTreeMap::new(); map.insert(1, "a"); assert_eq!(map.get(&1), Some(&"a")); assert_eq!(map.get(&2), None);
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.
Examples
use std::collections::BTreeMap; let mut map = BTreeMap::new(); map.insert(1, "a"); assert_eq!(map.get_key_value(&1), Some((&1, &"a"))); assert_eq!(map.get_key_value(&2), None);
🔬 This is a nightly-only experimental API. (map_first_last
)
map_first_last
)Returns the first key-value pair in the map. The key in this pair is the minimum key in the map.
Examples
Basic usage:
#![feature(map_first_last)] use std::collections::BTreeMap; let mut map = BTreeMap::new(); assert_eq!(map.first_key_value(), None); map.insert(1, "b"); map.insert(2, "a"); assert_eq!(map.first_key_value(), Some((&1, &"b")));
🔬 This is a nightly-only experimental API. (map_first_last
)
map_first_last
)Returns the last key-value pair in the map. The key in this pair is the maximum key in the map.
Examples
Basic usage:
#![feature(map_first_last)] use std::collections::BTreeMap; let mut map = BTreeMap::new(); map.insert(1, "b"); map.insert(2, "a"); assert_eq!(map.last_key_value(), Some((&2, &"a")));
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.
Examples
Basic usage:
use std::collections::BTreeMap; let mut map = BTreeMap::new(); map.insert(1, "a"); assert_eq!(map.contains_key(&1), true); assert_eq!(map.contains_key(&2), false);
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.
Panics
Panics if range start > end
.
Panics if range start == end
and both bounds are Excluded
.
Examples
Basic usage:
use std::collections::BTreeMap; use std::ops::Bound::Included; let mut map = BTreeMap::new(); map.insert(3, "a"); map.insert(5, "b"); map.insert(8, "c"); for (&key, &value) in map.range((Included(&4), Included(&8))) { println!("{}: {}", key, value); } assert_eq!(Some((&5, &"b")), map.range(4..).next());
Gets an iterator over the entries of the map, sorted by key.
Examples
Basic usage:
use std::collections::BTreeMap; let mut map = BTreeMap::new(); map.insert(3, "c"); map.insert(2, "b"); map.insert(1, "a"); for (key, value) in map.iter() { println!("{}: {}", key, value); } let (first_key, first_value) = map.iter().next().unwrap(); assert_eq!((*first_key, *first_value), (1, "a"));
Gets an iterator over the keys of the map, in sorted order.
Examples
Basic usage:
use std::collections::BTreeMap; let mut a = BTreeMap::new(); a.insert(2, "b"); a.insert(1, "a"); let keys: Vec<_> = a.keys().cloned().collect(); assert_eq!(keys, [1, 2]);
Gets an iterator over the values of the map, in order by key.
Examples
Basic usage:
use std::collections::BTreeMap; let mut a = BTreeMap::new(); a.insert(1, "hello"); a.insert(2, "goodbye"); let values: Vec<&str> = a.values().cloned().collect(); assert_eq!(values, ["hello", "goodbye"]);
Returns the number of elements in the map.
Examples
Basic usage:
use std::collections::BTreeMap; let mut a = BTreeMap::new(); assert_eq!(a.len(), 0); a.insert(1, "a"); assert_eq!(a.len(), 1);
Trait Implementations
Attempt to deserialise the value from input.
Attempt to skip the encoded value from input. Read more
fn encoded_fixed_size() -> Option<usize>
fn encoded_fixed_size() -> Option<usize>
Returns the fixed encoded size of the type. Read more
impl<K, V, S> Encode for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: Encode,
BTreeMap<K, V>: Encode,
PhantomData<S>: Encode,
PhantomData<S>: Encode,
impl<K, V, S> Encode for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: Encode,
BTreeMap<K, V>: Encode,
PhantomData<S>: Encode,
PhantomData<S>: Encode,
Convert self to a slice and append it to the destination.
Convert self to an owned vector.
fn using_encoded<R, F>(&self, f: F) -> R where
F: FnOnce(&[u8]) -> R,
fn using_encoded<R, F>(&self, f: F) -> R where
F: FnOnce(&[u8]) -> R,
Convert self to a slice and then invoke the given closure with it.
fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
Performs the conversion.
impl<K, V, S> MaxEncodedLen for BoundedBTreeMap<K, V, S> where
K: MaxEncodedLen,
V: MaxEncodedLen,
S: Get<u32>,
impl<K, V, S> MaxEncodedLen for BoundedBTreeMap<K, V, S> where
K: MaxEncodedLen,
V: MaxEncodedLen,
S: Get<u32>,
Upper bound, in bytes, of the maximum encoded size of this item.
impl<K, V, S> PartialEq<BoundedBTreeMap<K, V, S>> for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: PartialEq,
impl<K, V, S> PartialEq<BoundedBTreeMap<K, V, S>> for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: PartialEq,
impl<K, V, S> PartialOrd<BoundedBTreeMap<K, V, S>> for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: PartialOrd,
impl<K, V, S> PartialOrd<BoundedBTreeMap<K, V, S>> for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: PartialOrd,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<K, V, S> EncodeLike<BTreeMap<K, V>> for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: Encode,
impl<K, V, S> EncodeLike<BoundedBTreeMap<K, V, S>> for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: Encode,
BTreeMap<K, V>: Encode,
PhantomData<S>: Encode,
PhantomData<S>: Encode,
Auto Trait Implementations
impl<K, V, S> RefUnwindSafe for BoundedBTreeMap<K, V, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, S> Send for BoundedBTreeMap<K, V, S> where
K: Send,
S: Send,
V: Send,
impl<K, V, S> Sync for BoundedBTreeMap<K, V, S> where
K: Sync,
S: Sync,
V: Sync,
impl<K, V, S> Unpin for BoundedBTreeMap<K, V, S> where
S: Unpin,
impl<K, V, S> UnwindSafe for BoundedBTreeMap<K, V, S> where
K: RefUnwindSafe,
S: UnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> DecodeAll for T where
T: Decode,
impl<T> DecodeAll for T where
T: Decode,
impl<T> DecodeLimit for T where
T: Decode,
impl<T> DecodeLimit for T where
T: Decode,
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
impl<T> KeyedVec for T where
T: Codec,
impl<T> KeyedVec for T where
T: Codec,
type Output = T
type Output = T
Should always be Self
The counterpart to unchecked_from
.
Consume self to return an equivalent value of T
.
pub fn vzip(self) -> V
impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
T: Encode,
impl<'_, T> EncodeLike<&'_ T> for T where
T: Encode,
impl<'_, T> EncodeLike<&'_ mut T> for T where
T: Encode,
impl<T> EncodeLike<Arc<T>> for T where
T: Encode,
impl<T> EncodeLike<Box<T, Global>> for T where
T: Encode,
impl<'a, T> EncodeLike<Cow<'a, T>> for T where
T: ToOwned + Encode,
impl<T> EncodeLike<Rc<T>> for T where
T: Encode,
impl<S> FullCodec for S where
S: Decode + FullEncode,
impl<S> FullEncode for S where
S: Encode + EncodeLike<S>,
impl<T> MaybeDebug for T where
T: Debug,
impl<T> MaybeDebug for T where
T: Debug,