Struct im_rc::ordset::OrdSet [−][src]
An ordered set.
An immutable ordered set implemented as a [B-tree] 1.
Most operations on this type of set are O(log n). A
HashSet
is usually a better choice for
performance, but the OrdSet
has the advantage of only requiring
an Ord
constraint on its values, and of being
ordered, so values always come out from lowest to highest, where a
HashSet
has no guaranteed ordering.
Implementations
impl<A> OrdSet<A>
[src]
#[must_use]pub fn new() -> Self
[src]
Construct an empty set.
#[must_use]pub fn unit(a: A) -> Self
[src]
Construct a set with a single value.
Examples
let set = OrdSet::unit(123); assert!(set.contains(&123));
#[must_use]pub fn is_empty(&self) -> bool
[src]
Test whether a set is empty.
Time: O(1)
Examples
assert!( !ordset![1, 2, 3].is_empty() ); assert!( OrdSet::<i32>::new().is_empty() );
#[must_use]pub fn len(&self) -> usize
[src]
pub fn ptr_eq(&self, other: &Self) -> bool
[src]
Test whether two sets refer to the same content in memory.
This is true if the two sides are references to the same set, or if the two sets refer to the same root node.
This would return true if you’re comparing a set to itself, or if you’re comparing a set to a fresh clone of itself.
Time: O(1)
pub fn clear(&mut self)
[src]
Discard all elements from the set.
This leaves you with an empty set, and all elements that were previously inside it are dropped.
Time: O(n)
Examples
let mut set = ordset![1, 2, 3]; set.clear(); assert!(set.is_empty());
impl<A> OrdSet<A> where
A: Ord,
[src]
A: Ord,
#[must_use]pub fn get_min(&self) -> Option<&A>
[src]
Get the smallest value in a set.
If the set is empty, returns None
.
Time: O(log n)
#[must_use]pub fn get_max(&self) -> Option<&A>
[src]
Get the largest value in a set.
If the set is empty, returns None
.
Time: O(log n)
#[must_use]pub fn iter(&self) -> Iter<'_, A>ⓘ
[src]
Create an iterator over the contents of the set.
#[must_use]pub fn range<R, BA: ?Sized>(&self, range: R) -> RangedIter<'_, A>ⓘNotable traits for RangedIter<'a, A>
impl<'a, A> Iterator for RangedIter<'a, A> where
A: 'a + Ord, type Item = &'a A;
where
R: RangeBounds<BA>,
A: Borrow<BA>,
BA: Ord,
[src]
Notable traits for RangedIter<'a, A>
impl<'a, A> Iterator for RangedIter<'a, A> where
A: 'a + Ord, type Item = &'a A;
R: RangeBounds<BA>,
A: Borrow<BA>,
BA: Ord,
Create an iterator over a range inside the set.
#[must_use]pub fn diff<'a>(&'a self, other: &'a Self) -> DiffIter<'_, A>ⓘ
[src]
Get an iterator over the differences between this set and another, i.e. the set of entries to add or remove to this set in order to make it equal to the other set.
This function will avoid visiting nodes which are shared between the two sets, meaning that even very large sets can be compared quickly if most of their structure is shared.
Time: O(n) (where n is the number of unique elements across the two sets, minus the number of elements belonging to nodes shared between them)
#[must_use]pub fn contains<BA: ?Sized>(&self, a: &BA) -> bool where
BA: Ord,
A: Borrow<BA>,
[src]
BA: Ord,
A: Borrow<BA>,
Test if a value is part of a set.
Time: O(log n)
Examples
let mut set = ordset!{1, 2, 3}; assert!(set.contains(&1)); assert!(!set.contains(&4));
#[must_use]pub fn get_prev(&self, key: &A) -> Option<&A>
[src]
Get the closest smaller value in a set to a given value.
If the set contains the given value, this is returned.
Otherwise, the closest value in the set smaller than the
given value is returned. If the smallest value in the set
is larger than the given value, None
is returned.
Examples
let set = ordset![1, 3, 5, 7, 9]; assert_eq!(Some(&5), set.get_prev(&6));
#[must_use]pub fn get_next(&self, key: &A) -> Option<&A>
[src]
Get the closest larger value in a set to a given value.
If the set contains the given value, this is returned.
Otherwise, the closest value in the set larger than the
given value is returned. If the largest value in the set
is smaller than the given value, None
is returned.
Examples
let set = ordset![1, 3, 5, 7, 9]; assert_eq!(Some(&5), set.get_next(&4));
#[must_use]pub fn is_subset<RS>(&self, other: RS) -> bool where
RS: Borrow<Self>,
[src]
RS: Borrow<Self>,
Test whether a set is a subset of another set, meaning that all values in our set must also be in the other set.
Time: O(n log m) where m is the size of the other set
#[must_use]pub fn is_proper_subset<RS>(&self, other: RS) -> bool where
RS: Borrow<Self>,
[src]
RS: Borrow<Self>,
Test whether a set is a proper subset of another set, meaning that all values in our set must also be in the other set. A proper subset must also be smaller than the other set.
Time: O(n log m) where m is the size of the other set
impl<A> OrdSet<A> where
A: Ord + Clone,
[src]
A: Ord + Clone,
pub fn insert(&mut self, a: A) -> Option<A>
[src]
Insert a value into a set.
Time: O(log n)
Examples
let mut set = ordset!{}; set.insert(123); set.insert(456); assert_eq!( set, ordset![123, 456] );
pub fn remove<BA: ?Sized>(&mut self, a: &BA) -> Option<A> where
BA: Ord,
A: Borrow<BA>,
[src]
BA: Ord,
A: Borrow<BA>,
Remove a value from a set.
Time: O(log n)
pub fn remove_min(&mut self) -> Option<A>
[src]
Remove the smallest value from a set.
Time: O(log n)
pub fn remove_max(&mut self) -> Option<A>
[src]
Remove the largest value from a set.
Time: O(log n)
#[must_use]pub fn update(&self, a: A) -> Self
[src]
Construct a new set from the current set with the given value added.
Time: O(log n)
Examples
let set = ordset![456]; assert_eq!( set.update(123), ordset![123, 456] );
#[must_use]pub fn without<BA: ?Sized>(&self, a: &BA) -> Self where
BA: Ord,
A: Borrow<BA>,
[src]
BA: Ord,
A: Borrow<BA>,
Construct a new set with the given value removed if it’s in the set.
Time: O(log n)
#[must_use]pub fn without_min(&self) -> (Option<A>, Self)
[src]
Remove the smallest value from a set, and return that value as well as the updated set.
Time: O(log n)
#[must_use]pub fn without_max(&self) -> (Option<A>, Self)
[src]
Remove the largest value from a set, and return that value as well as the updated set.
Time: O(log n)
#[must_use]pub fn union(self, other: Self) -> Self
[src]
Construct the union of two sets.
Time: O(n log n)
Examples
let set1 = ordset!{1, 2}; let set2 = ordset!{2, 3}; let expected = ordset!{1, 2, 3}; assert_eq!(expected, set1.union(set2));
#[must_use]pub fn unions<I>(i: I) -> Self where
I: IntoIterator<Item = Self>,
[src]
I: IntoIterator<Item = Self>,
Construct the union of multiple sets.
Time: O(n log n)
#[must_use]pub fn difference(self, other: Self) -> Self
[src]
Construct the symmetric difference between two sets.
This is an alias for the
symmetric_difference
method.
Time: O(n log n)
Examples
let set1 = ordset!{1, 2}; let set2 = ordset!{2, 3}; let expected = ordset!{1, 3}; assert_eq!(expected, set1.difference(set2));
#[must_use]pub fn symmetric_difference(self, other: Self) -> Self
[src]
Construct the symmetric difference between two sets.
Time: O(n log n)
Examples
let set1 = ordset!{1, 2}; let set2 = ordset!{2, 3}; let expected = ordset!{1, 3}; assert_eq!(expected, set1.symmetric_difference(set2));
#[must_use]pub fn relative_complement(self, other: Self) -> Self
[src]
Construct the relative complement between two sets, that is the set
of values in self
that do not occur in other
.
Time: O(m log n) where m is the size of the other set
Examples
let set1 = ordset!{1, 2}; let set2 = ordset!{2, 3}; let expected = ordset!{1}; assert_eq!(expected, set1.relative_complement(set2));
#[must_use]pub fn intersection(self, other: Self) -> Self
[src]
Construct the intersection of two sets.
Time: O(n log n)
Examples
let set1 = ordset!{1, 2}; let set2 = ordset!{2, 3}; let expected = ordset!{2}; assert_eq!(expected, set1.intersection(set2));
#[must_use]pub fn split<BA: ?Sized>(self, split: &BA) -> (Self, Self) where
BA: Ord,
A: Borrow<BA>,
[src]
BA: Ord,
A: Borrow<BA>,
Split a set into two, with the left hand set containing values
which are smaller than split
, and the right hand set
containing values which are larger than split
.
The split
value itself is discarded.
Time: O(n)
#[must_use]pub fn split_member<BA: ?Sized>(self, split: &BA) -> (Self, bool, Self) where
BA: Ord,
A: Borrow<BA>,
[src]
BA: Ord,
A: Borrow<BA>,
Split a set into two, with the left hand set containing values
which are smaller than split
, and the right hand set
containing values which are larger than split
.
Returns a tuple of the two sets and a boolean which is true if
the split
value existed in the original set, and false
otherwise.
Time: O(n)
#[must_use]pub fn take(&self, n: usize) -> Self
[src]
Construct a set with only the n
smallest values from a given
set.
Time: O(n)
#[must_use]pub fn skip(&self, n: usize) -> Self
[src]
Construct a set with the n
smallest values removed from a
given set.
Time: O(n)
Trait Implementations
impl<'a, A: Ord + Clone> Add<&'a OrdSet<A>> for &'a OrdSet<A>
[src]
type Output = OrdSet<A>
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
impl<A: Ord + Clone> Add<OrdSet<A>> for OrdSet<A>
[src]
type Output = OrdSet<A>
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
impl<A> Clone for OrdSet<A>
[src]
fn clone(&self) -> Self
[src]
Clone a set.
Time: O(1)
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A: Ord + Debug> Debug for OrdSet<A>
[src]
impl<A> Default for OrdSet<A>
[src]
impl<A: Ord + Eq> Eq for OrdSet<A>
[src]
impl<A, R> Extend<R> for OrdSet<A> where
A: Ord + Clone + From<R>,
[src]
A: Ord + Clone + From<R>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = R>,
[src]
I: IntoIterator<Item = R>,
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<'a, A> From<&'a [A]> for OrdSet<A> where
A: Ord + Clone,
[src]
A: Ord + Clone,
impl<'a, A: Ord + Clone> From<&'a BTreeSet<A>> for OrdSet<A>
[src]
impl<'a, A: Eq + Hash + Ord + Clone> From<&'a HashSet<A, RandomState>> for OrdSet<A>
[src]
impl<'a, A: Hash + Eq + Ord + Clone, S: BuildHasher> From<&'a HashSet<A, S>> for OrdSet<A>
[src]
impl<'a, A, S> From<&'a OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
impl<'a, A: Ord + Clone> From<&'a Vec<A, Global>> for OrdSet<A>
[src]
impl<'s, 'a, A: ?Sized, OA> From<&'s OrdSet<&'a A>> for OrdSet<OA> where
A: ToOwned<Owned = OA> + Ord,
OA: Borrow<A> + Ord + Clone,
[src]
A: ToOwned<Owned = OA> + Ord,
OA: Borrow<A> + Ord + Clone,
impl<A: Ord + Clone> From<BTreeSet<A>> for OrdSet<A>
[src]
impl<A: Eq + Hash + Ord + Clone> From<HashSet<A, RandomState>> for OrdSet<A>
[src]
impl<A: Hash + Eq + Ord + Clone, S: BuildHasher> From<HashSet<A, S>> for OrdSet<A>
[src]
impl<A, S> From<OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
impl<A: Ord + Clone> From<Vec<A, Global>> for OrdSet<A>
[src]
impl<A, R> FromIterator<R> for OrdSet<A> where
A: Ord + Clone + From<R>,
[src]
A: Ord + Clone + From<R>,
fn from_iter<T>(i: T) -> Self where
T: IntoIterator<Item = R>,
[src]
T: IntoIterator<Item = R>,
impl<A: Ord + Hash> Hash for OrdSet<A>
[src]
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a, A> IntoIterator for &'a OrdSet<A> where
A: 'a + Ord,
[src]
A: 'a + Ord,
type Item = &'a A
The type of the elements being iterated over.
type IntoIter = Iter<'a, A>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<A> IntoIterator for OrdSet<A> where
A: Ord + Clone,
[src]
A: Ord + Clone,
type Item = A
The type of the elements being iterated over.
type IntoIter = ConsumingIter<A>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, A: Ord + Clone> Mul<&'a OrdSet<A>> for &'a OrdSet<A>
[src]
type Output = OrdSet<A>
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self::Output
[src]
impl<A: Ord + Clone> Mul<OrdSet<A>> for OrdSet<A>
[src]
type Output = OrdSet<A>
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self::Output
[src]
impl<A: Ord> Ord for OrdSet<A>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<A: Ord> PartialEq<OrdSet<A>> for OrdSet<A>
[src]
impl<A: Ord> PartialOrd<OrdSet<A>> for OrdSet<A>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A: Ord + Clone> Sum<OrdSet<A>> for OrdSet<A>
[src]
Auto Trait Implementations
impl<A> !RefUnwindSafe for OrdSet<A>
impl<A> !Send for OrdSet<A>
impl<A> !Sync for OrdSet<A>
impl<A> Unpin for OrdSet<A> where
A: Unpin,
A: Unpin,
impl<A> !UnwindSafe for OrdSet<A>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,