Struct frame_support::storage::bounded_btree_set::BoundedBTreeSet [−][src]
pub struct BoundedBTreeSet<T, S>(_, _);
Expand description
A bounded set 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 BTreeSet
for more details.
Unlike a standard BTreeSet
, there is an enforced upper limit to the number of items in the
set. All internal operations ensure this bound is respected.
Implementations
Consume self, and return the inner BTreeSet
.
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
.
Exactly the same semantics as BTreeSet::insert
, but returns an Err
(and is a noop) if
the new length of the set exceeds S
.
In the Err
case, returns the inserted item so it can be further used without cloning.
Remove an item from the set, returning whether it was previously in the set.
The item may be any borrowed form of the set’s item type, but the ordering on the borrowed form must match the ordering on the item type.
Removes and returns the value in the set, if any, that is equal to the given one.
The value may be any borrowed form of the set’s value type, but the ordering on the borrowed form must match the ordering on the value type.
Methods from Deref<Target = BTreeSet<T>>
Constructs a double-ended iterator over a sub-range of elements in the set.
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.
Examples
use std::collections::BTreeSet; use std::ops::Bound::Included; let mut set = BTreeSet::new(); set.insert(3); set.insert(5); set.insert(8); for &elem in set.range((Included(&4), Included(&8))) { println!("{}", elem); } assert_eq!(Some(&5), set.range(4..).next());
Visits the values representing the difference,
i.e., the values that are in self
but not in other
,
in ascending order.
Examples
use std::collections::BTreeSet; let mut a = BTreeSet::new(); a.insert(1); a.insert(2); let mut b = BTreeSet::new(); b.insert(2); b.insert(3); let diff: Vec<_> = a.difference(&b).cloned().collect(); assert_eq!(diff, [1]);
1.0.0[src]pub fn symmetric_difference(
&'a self,
other: &'a BTreeSet<T>
) -> SymmetricDifference<'a, T> where
T: Ord,
pub fn symmetric_difference(
&'a self,
other: &'a BTreeSet<T>
) -> SymmetricDifference<'a, T> where
T: Ord,
Visits the values representing the symmetric difference,
i.e., the values that are in self
or in other
but not in both,
in ascending order.
Examples
use std::collections::BTreeSet; let mut a = BTreeSet::new(); a.insert(1); a.insert(2); let mut b = BTreeSet::new(); b.insert(2); b.insert(3); let sym_diff: Vec<_> = a.symmetric_difference(&b).cloned().collect(); assert_eq!(sym_diff, [1, 3]);
1.0.0[src]pub fn intersection(&'a self, other: &'a BTreeSet<T>) -> Intersection<'a, T> where
T: Ord,
pub fn intersection(&'a self, other: &'a BTreeSet<T>) -> Intersection<'a, T> where
T: Ord,
Visits the values representing the intersection,
i.e., the values that are both in self
and other
,
in ascending order.
Examples
use std::collections::BTreeSet; let mut a = BTreeSet::new(); a.insert(1); a.insert(2); let mut b = BTreeSet::new(); b.insert(2); b.insert(3); let intersection: Vec<_> = a.intersection(&b).cloned().collect(); assert_eq!(intersection, [2]);
Visits the values representing the union,
i.e., all the values in self
or other
, without duplicates,
in ascending order.
Examples
use std::collections::BTreeSet; let mut a = BTreeSet::new(); a.insert(1); let mut b = BTreeSet::new(); b.insert(2); let union: Vec<_> = a.union(&b).cloned().collect(); assert_eq!(union, [1, 2]);
Returns true
if the set contains a value.
The value may be any borrowed form of the set’s value type, but the ordering on the borrowed form must match the ordering on the value type.
Examples
use std::collections::BTreeSet; let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); assert_eq!(set.contains(&1), true); assert_eq!(set.contains(&4), false);
Returns a reference to the value in the set, if any, that is equal to the given value.
The value may be any borrowed form of the set’s value type, but the ordering on the borrowed form must match the ordering on the value type.
Examples
use std::collections::BTreeSet; let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); assert_eq!(set.get(&2), Some(&2)); assert_eq!(set.get(&4), None);
Returns true
if self
has no elements in common with other
.
This is equivalent to checking for an empty intersection.
Examples
use std::collections::BTreeSet; let a: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); let mut b = BTreeSet::new(); assert_eq!(a.is_disjoint(&b), true); b.insert(4); assert_eq!(a.is_disjoint(&b), true); b.insert(1); assert_eq!(a.is_disjoint(&b), false);
Returns true
if the set is a subset of another,
i.e., other
contains at least all the values in self
.
Examples
use std::collections::BTreeSet; let sup: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); let mut set = BTreeSet::new(); assert_eq!(set.is_subset(&sup), true); set.insert(2); assert_eq!(set.is_subset(&sup), true); set.insert(4); assert_eq!(set.is_subset(&sup), false);
Returns true
if the set is a superset of another,
i.e., self
contains at least all the values in other
.
Examples
use std::collections::BTreeSet; let sub: BTreeSet<_> = [1, 2].iter().cloned().collect(); let mut set = BTreeSet::new(); assert_eq!(set.is_superset(&sub), false); set.insert(0); set.insert(1); assert_eq!(set.is_superset(&sub), false); set.insert(2); assert_eq!(set.is_superset(&sub), true);
🔬 This is a nightly-only experimental API. (map_first_last
)
map_first_last
)Returns a reference to the first value in the set, if any. This value is always the minimum of all values in the set.
Examples
Basic usage:
#![feature(map_first_last)] use std::collections::BTreeSet; let mut set = BTreeSet::new(); assert_eq!(set.first(), None); set.insert(1); assert_eq!(set.first(), Some(&1)); set.insert(2); assert_eq!(set.first(), Some(&1));
🔬 This is a nightly-only experimental API. (map_first_last
)
map_first_last
)Returns a reference to the last value in the set, if any. This value is always the maximum of all values in the set.
Examples
Basic usage:
#![feature(map_first_last)] use std::collections::BTreeSet; let mut set = BTreeSet::new(); assert_eq!(set.last(), None); set.insert(1); assert_eq!(set.last(), Some(&1)); set.insert(2); assert_eq!(set.last(), Some(&2));
Gets an iterator that visits the values in the BTreeSet
in ascending order.
Examples
use std::collections::BTreeSet; let set: BTreeSet<usize> = [1, 2, 3].iter().cloned().collect(); let mut set_iter = set.iter(); assert_eq!(set_iter.next(), Some(&1)); assert_eq!(set_iter.next(), Some(&2)); assert_eq!(set_iter.next(), Some(&3)); assert_eq!(set_iter.next(), None);
Values returned by the iterator are returned in ascending order:
use std::collections::BTreeSet; let set: BTreeSet<usize> = [3, 1, 2].iter().cloned().collect(); let mut set_iter = set.iter(); assert_eq!(set_iter.next(), Some(&1)); assert_eq!(set_iter.next(), Some(&2)); assert_eq!(set_iter.next(), Some(&3)); assert_eq!(set_iter.next(), None);
Returns the number of elements in the set.
Examples
use std::collections::BTreeSet; let mut v = BTreeSet::new(); assert_eq!(v.len(), 0); v.insert(1); assert_eq!(v.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<T, S> Encode for BoundedBTreeSet<T, S> where
BTreeSet<T>: Encode,
BTreeSet<T>: Encode,
PhantomData<S>: Encode,
PhantomData<S>: Encode,
impl<T, S> Encode for BoundedBTreeSet<T, S> where
BTreeSet<T>: Encode,
BTreeSet<T>: 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.
Upper bound, in bytes, of the maximum encoded size of this item.
impl<T, S> PartialEq<BoundedBTreeSet<T, S>> for BoundedBTreeSet<T, S> where
BTreeSet<T>: PartialEq,
impl<T, S> PartialEq<BoundedBTreeSet<T, S>> for BoundedBTreeSet<T, S> where
BTreeSet<T>: PartialEq,
impl<T, S> PartialOrd<BoundedBTreeSet<T, S>> for BoundedBTreeSet<T, S> where
BTreeSet<T>: PartialOrd,
impl<T, S> PartialOrd<BoundedBTreeSet<T, S>> for BoundedBTreeSet<T, S> where
BTreeSet<T>: 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<T, S> EncodeLike<BoundedBTreeSet<T, S>> for BoundedBTreeSet<T, S> where
BTreeSet<T>: Encode,
BTreeSet<T>: Encode,
PhantomData<S>: Encode,
PhantomData<S>: Encode,
Auto Trait Implementations
impl<T, S> RefUnwindSafe for BoundedBTreeSet<T, S> where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for BoundedBTreeSet<T, S> where
S: Send,
T: Send,
impl<T, S> Sync for BoundedBTreeSet<T, S> where
S: Sync,
T: Sync,
impl<T, S> Unpin for BoundedBTreeSet<T, S> where
S: Unpin,
impl<T, S> UnwindSafe for BoundedBTreeSet<T, S> where
S: UnwindSafe,
T: 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,