Struct frame_support::storage::bounded_btree_map::BoundedBTreeMap
source · [−]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
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,
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> TypeInfo for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: TypeInfo + 'static,
PhantomData<S>: TypeInfo + 'static,
K: TypeInfo + 'static,
V: TypeInfo + 'static,
S: 'static,
impl<K, V, S> TypeInfo for BoundedBTreeMap<K, V, S> where
BTreeMap<K, V>: TypeInfo + 'static,
PhantomData<S>: TypeInfo + 'static,
K: TypeInfo + 'static,
V: TypeInfo + 'static,
S: 'static,
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
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
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
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
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
The counterpart to unchecked_from
.
Consume self to return an equivalent value of T
.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more