Struct frame_support::storage::bounded_btree_set::BoundedBTreeSet
source · [−]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());
1.0.0 · sourcepub fn difference(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T> where
T: Ord,
pub fn difference(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T> where
T: Ord,
Visits the elements representing the difference,
i.e., the elements 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 · sourcepub 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 elements representing the symmetric difference,
i.e., the elements 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 · sourcepub 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 elements representing the intersection,
i.e., the elements 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 elements representing the union,
i.e., all the elements 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 an element equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form must match the ordering on the element type.
Examples
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
assert_eq!(set.contains(&1), true);
assert_eq!(set.contains(&4), false);
Returns a reference to the element in the set, if any, that is equal to the value.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form must match the ordering on the element type.
Examples
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
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::from([1, 2, 3]);
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 elements in self
.
Examples
use std::collections::BTreeSet;
let sup = BTreeSet::from([1, 2, 3]);
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 elements in other
.
Examples
use std::collections::BTreeSet;
let sub = BTreeSet::from([1, 2]);
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 element in the set, if any. This element is always the minimum of all elements 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 element in the set, if any. This element is always the maximum of all elements 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 elements in the BTreeSet
in ascending
order.
Examples
use std::collections::BTreeSet;
let set = BTreeSet::from([1, 2, 3]);
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::from([3, 1, 2]);
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
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,
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> TypeInfo for BoundedBTreeSet<T, S> where
BTreeSet<T>: TypeInfo + 'static,
PhantomData<S>: TypeInfo + 'static,
T: TypeInfo + 'static,
S: 'static,
impl<T, S> TypeInfo for BoundedBTreeSet<T, S> where
BTreeSet<T>: TypeInfo + 'static,
PhantomData<S>: TypeInfo + 'static,
T: TypeInfo + 'static,
S: 'static,
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
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