Struct im::ordset::OrdSet [−][src]
pub struct OrdSet<A> { /* fields omitted */ }
An ordered set.
An immutable ordered set implemented as a B-tree.
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.
Methods
impl<A> OrdSet<A>
[src]
impl<A> OrdSet<A>
pub fn new() -> Self
[src]
pub fn new() -> Self
Construct an empty set.
pub fn singleton(a: A) -> Self
[src]
pub fn singleton(a: A) -> Self
Construct a set with a single value.
Examples
let set = OrdSet::singleton(123); assert!(set.contains(&123));
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Test whether a set is empty.
Time: O(1)
Examples
assert!( !ordset![1, 2, 3].is_empty() ); assert!( OrdSet::<i32>::new().is_empty() );
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
pub fn get_min(&self) -> Option<&A>
[src]
pub fn get_min(&self) -> Option<&A>
Get the smallest value in a set.
If the set is empty, returns None
.
pub fn get_max(&self) -> Option<&A>
[src]
pub fn get_max(&self) -> Option<&A>
Get the largest value in a set.
If the set is empty, returns None
.
impl<A: Ord + Clone> OrdSet<A>
[src]
impl<A: Ord + Clone> OrdSet<A>
ⓘImportant traits for Iter<'a, A>pub fn iter(&self) -> Iter<A>
[src]
pub fn iter(&self) -> Iter<A>
ⓘImportant traits for DiffIter<'a, A>pub fn diff<'a>(&'a self, other: &'a Self) -> DiffIter<A>
[src]
pub fn diff<'a>(&'a self, other: &'a Self) -> DiffIter<A>
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)
pub fn contains<BA: ?Sized>(&self, a: &BA) -> bool where
BA: Ord,
A: Borrow<BA>,
[src]
pub fn contains<BA: ?Sized>(&self, a: &BA) -> bool where
BA: Ord,
A: Borrow<BA>,
Test if a value is part of a set.
Time: O(log n)
pub fn insert(&mut self, a: A) -> Option<A>
[src]
pub fn insert(&mut self, a: A) -> Option<A>
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]
pub fn remove<BA: ?Sized>(&mut self, a: &BA) -> Option<A> where
BA: Ord,
A: Borrow<BA>,
Remove a value from a set.
Time: O(log n)
pub fn remove_min(&mut self) -> Option<A>
[src]
pub fn remove_min(&mut self) -> Option<A>
Remove the smallest value from a set.
Time: O(log n)
pub fn remove_max(&mut self) -> Option<A>
[src]
pub fn remove_max(&mut self) -> Option<A>
Remove the largest value from a set.
Time: O(log n)
pub fn update(&self, a: A) -> Self
[src]
pub fn update(&self, a: A) -> Self
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] );
pub fn without<BA: ?Sized>(&self, a: &BA) -> Self where
BA: Ord,
A: Borrow<BA>,
[src]
pub fn without<BA: ?Sized>(&self, a: &BA) -> Self where
BA: Ord,
A: Borrow<BA>,
Construct a new set with the given value removed if it's in the set.
Time: O(log n)
pub fn without_min(&self) -> (Option<A>, Self)
[src]
pub fn without_min(&self) -> (Option<A>, Self)
Remove the smallest value from a set, and return that value as well as the updated set.
Time: O(log n)
pub fn without_max(&self) -> (Option<A>, Self)
[src]
pub fn without_max(&self) -> (Option<A>, Self)
Remove the largest value from a set, and return that value as well as the updated set.
Time: O(log n)
pub fn union(self, other: Self) -> Self
[src]
pub fn union(self, other: Self) -> Self
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));
pub fn unions<I>(i: I) -> Self where
I: IntoIterator<Item = Self>,
[src]
pub fn unions<I>(i: I) -> Self where
I: IntoIterator<Item = Self>,
Construct the union of multiple sets.
Time: O(n log n)
pub fn difference(self, other: Self) -> Self
[src]
pub fn difference(self, other: Self) -> Self
Construct the 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.difference(set2));
pub fn intersection(self, other: Self) -> Self
[src]
pub fn intersection(self, other: Self) -> Self
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));
pub fn is_subset<RS>(&self, other: RS) -> bool where
RS: Borrow<Self>,
[src]
pub fn is_subset<RS>(&self, other: RS) -> bool where
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 n)
pub fn is_proper_subset<RS>(&self, other: RS) -> bool where
RS: Borrow<Self>,
[src]
pub fn is_proper_subset<RS>(&self, other: RS) -> bool where
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 n)
pub fn split<BA: ?Sized>(self, split: &BA) -> (Self, Self) where
BA: Ord,
A: Borrow<BA>,
[src]
pub fn split<BA: ?Sized>(self, split: &BA) -> (Self, Self) where
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)
pub fn split_member<BA: ?Sized>(self, split: &BA) -> (Self, bool, Self) where
BA: Ord,
A: Borrow<BA>,
[src]
pub fn split_member<BA: ?Sized>(self, split: &BA) -> (Self, bool, Self) where
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)
pub fn take(&self, n: usize) -> Self
[src]
pub fn take(&self, n: usize) -> Self
Construct a set with only the n
smallest values from a given
set.
Time: O(n)
pub fn skip(&self, n: usize) -> Self
[src]
pub fn skip(&self, n: usize) -> Self
Construct a set with the n
smallest values removed from a
given set.
Time: O(n)
Trait Implementations
impl<A> Clone for OrdSet<A>
[src]
impl<A> Clone for OrdSet<A>
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<A: Ord + Clone> PartialEq for OrdSet<A>
[src]
impl<A: Ord + Clone> PartialEq for OrdSet<A>
fn eq(&self, other: &Self) -> bool
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<A: Ord + Eq + Clone> Eq for OrdSet<A>
[src]
impl<A: Ord + Eq + Clone> Eq for OrdSet<A>
impl<A: Ord + Clone> PartialOrd for OrdSet<A>
[src]
impl<A: Ord + Clone> PartialOrd for OrdSet<A>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<A: Ord + Clone> Ord for OrdSet<A>
[src]
impl<A: Ord + Clone> Ord for OrdSet<A>
fn cmp(&self, other: &Self) -> Ordering
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<A: Ord + Clone + Hash> Hash for OrdSet<A>
[src]
impl<A: Ord + Clone + Hash> Hash for OrdSet<A>
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
fn hash<H>(&self, state: &mut H) where
H: Hasher,
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<A> Default for OrdSet<A>
[src]
impl<A> Default for OrdSet<A>
impl<A: Ord + Clone> Add for OrdSet<A>
[src]
impl<A: Ord + Clone> Add for OrdSet<A>
type Output = OrdSet<A>
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
fn add(self, other: Self) -> Self::Output
Performs the +
operation.
impl<'a, A: Ord + Clone> Add for &'a OrdSet<A>
[src]
impl<'a, A: Ord + Clone> Add for &'a OrdSet<A>
type Output = OrdSet<A>
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
fn add(self, other: Self) -> Self::Output
Performs the +
operation.
impl<A: Ord + Clone> Mul for OrdSet<A>
[src]
impl<A: Ord + Clone> Mul for OrdSet<A>
type Output = OrdSet<A>
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self::Output
[src]
fn mul(self, other: Self) -> Self::Output
Performs the *
operation.
impl<'a, A: Ord + Clone> Mul for &'a OrdSet<A>
[src]
impl<'a, A: Ord + Clone> Mul for &'a OrdSet<A>
type Output = OrdSet<A>
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self::Output
[src]
fn mul(self, other: Self) -> Self::Output
Performs the *
operation.
impl<A: Ord + Clone> Sum for OrdSet<A>
[src]
impl<A: Ord + Clone> Sum for OrdSet<A>
fn sum<I>(it: I) -> Self where
I: Iterator<Item = Self>,
[src]
fn sum<I>(it: I) -> Self where
I: Iterator<Item = Self>,
Method which takes an iterator and generates Self
from the elements by "summing up" the items. Read more
impl<A, R> Extend<R> for OrdSet<A> where
A: Ord + Clone + From<R>,
[src]
impl<A, R> Extend<R> for OrdSet<A> where
A: Ord + Clone + From<R>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = R>,
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = R>,
Extends a collection with the contents of an iterator. Read more
impl<A: Ord + Clone + Debug> Debug for OrdSet<A>
[src]
impl<A: Ord + Clone + Debug> Debug for OrdSet<A>
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl<A, R> FromIterator<R> for OrdSet<A> where
A: Ord + Clone + From<R>,
[src]
impl<A, R> FromIterator<R> for OrdSet<A> where
A: Ord + Clone + From<R>,
fn from_iter<T>(i: T) -> Self where
T: IntoIterator<Item = R>,
[src]
fn from_iter<T>(i: T) -> Self where
T: IntoIterator<Item = R>,
Creates a value from an iterator. Read more
impl<'a, A> IntoIterator for &'a OrdSet<A> where
A: 'a + Ord + Clone,
[src]
impl<'a, A> IntoIterator for &'a OrdSet<A> where
A: 'a + Ord + Clone,
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]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<A> IntoIterator for OrdSet<A> where
A: Ord + Clone,
[src]
impl<A> IntoIterator for OrdSet<A> where
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]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
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]
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,
impl<'a, A> From<&'a [A]> for OrdSet<A> where
A: Ord + Clone,
[src]
impl<'a, A> From<&'a [A]> for OrdSet<A> where
A: Ord + Clone,
impl<A: Ord + Clone> From<Vec<A>> for OrdSet<A>
[src]
impl<A: Ord + Clone> From<Vec<A>> for OrdSet<A>
impl<'a, A: Ord + Clone> From<&'a Vec<A>> for OrdSet<A>
[src]
impl<'a, A: Ord + Clone> From<&'a Vec<A>> for OrdSet<A>
impl<A: Eq + Hash + Ord + Clone> From<HashSet<A>> for OrdSet<A>
[src]
impl<A: Eq + Hash + Ord + Clone> From<HashSet<A>> for OrdSet<A>
impl<'a, A: Eq + Hash + Ord + Clone> From<&'a HashSet<A>> for OrdSet<A>
[src]
impl<'a, A: Eq + Hash + Ord + Clone> From<&'a HashSet<A>> for OrdSet<A>
impl<A: Ord + Clone> From<BTreeSet<A>> for OrdSet<A>
[src]
impl<A: Ord + Clone> From<BTreeSet<A>> for OrdSet<A>
impl<'a, A: Ord + Clone> From<&'a BTreeSet<A>> for OrdSet<A>
[src]
impl<'a, A: Ord + Clone> From<&'a BTreeSet<A>> for OrdSet<A>
impl<A: Hash + Eq + Ord + Clone, S: BuildHasher> From<HashSet<A, S>> for OrdSet<A>
[src]
impl<A: Hash + Eq + Ord + Clone, S: BuildHasher> From<HashSet<A, S>> for OrdSet<A>
impl<'a, A: Hash + Eq + Ord + Clone, S: BuildHasher> From<&'a HashSet<A, S>> for OrdSet<A>
[src]
impl<'a, A: Hash + Eq + Ord + Clone, S: BuildHasher> From<&'a HashSet<A, S>> for OrdSet<A>
impl<A, S> From<OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<A, S> From<OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
impl<'a, A, S> From<&'a OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,
[src]
impl<'a, A, S> From<&'a OrdSet<A>> for HashSet<A, S> where
A: Ord + Hash + Eq + Clone,
S: BuildHasher + Default,