[−][src]Struct im::ordset::OrdSet
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> where
A: Ord + Clone,
[src]
impl<A> OrdSet<A> where
A: Ord + Clone,
| [src] |
Construct an empty set.
| [src] |
renamed to unit
for consistency
Construct a set with a single value.
This method has been deprecated; use unit
instead.
| [src] |
Construct a set with a single value.
Examples
let set = OrdSet::unit(123); assert!(set.contains(&123));
| [src] |
Test whether a set is empty.
Time: O(1)
Examples
assert!( !ordset![1, 2, 3].is_empty() ); assert!( OrdSet::<i32>::new().is_empty() );
| [src] |
| [src] |
Get the smallest value in a set.
If the set is empty, returns None
.
| [src] |
Get the largest value in a set.
If the set is empty, returns None
.
ⓘImportant traits for Iter<'a, A>
| [src] |
ⓘImportant traits for RangedIter<'a, A>
| [src] |
ⓘImportant traits for DiffIter<'a, 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)
| [src] |
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));
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 | [src] |
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)
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());
| [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] );
| [src] |
Construct a new set with the given value removed if it's in the set.
Time: O(log n)
| [src] |
Remove the smallest value from a set, and return that value as well as the updated set.
Time: O(log n)
| [src] |
Remove the largest value from a set, and return that value as well as the updated set.
Time: O(log n)
| [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));
| [src] |
Construct the union of multiple sets.
Time: O(n log n)
| [src] |
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));
| [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));
| [src] |
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)
| [src] |
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)
| [src] |
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)
| [src] |
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)
| [src] |
Construct a set with only the n
smallest values from a given
set.
Time: O(n)
| [src] |
Construct a set with the n
smallest values removed from a
given set.
Time: O(n)
Trait Implementations
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, RandomState>> for OrdSet<A>
[src]
impl<A: Eq + Hash + Ord + Clone> From<HashSet<A, RandomState>> for OrdSet<A>
impl<'a, A: Eq + Hash + Ord + Clone> From<&'a HashSet<A, RandomState>> for OrdSet<A>
[src]
impl<'a, A: Eq + Hash + Ord + Clone> From<&'a HashSet<A, RandomState>> 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,
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] |
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] |
impl<A: Ord + Eq + Clone> Eq for OrdSet<A>
[src]
impl<A: Ord + Eq + Clone> Eq for OrdSet<A>
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 | [src] |
impl<A: Ord + Clone> PartialOrd<OrdSet<A>> for OrdSet<A>
[src]
impl<A: Ord + Clone> PartialOrd<OrdSet<A>> for OrdSet<A>
fn partial_cmp(&self, other: &Self) -> Option<Ordering> | [src] |
| 1.0.0 [src] |
This method tests less than (for self
and other
) and is used by the <
operator. Read more
| 1.0.0 [src] |
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
| 1.0.0 [src] |
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
| 1.0.0 [src] |
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<A> Default for OrdSet<A> where
A: Ord + Clone,
[src]
impl<A> Default for OrdSet<A> where
A: Ord + Clone,
impl<A: Ord + Clone> PartialEq<OrdSet<A>> for OrdSet<A>
[src]
impl<A: Ord + Clone> PartialEq<OrdSet<A>> for OrdSet<A>
fn eq(&self, other: &Self) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl<A> Clone for OrdSet<A>
[src]
impl<A> Clone for OrdSet<A>
fn clone(&self) -> Self | [src] |
fn clone_from(&mut self, source: &Self) | 1.0.0 [src] |
Performs copy-assignment from source
. 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 max(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the minimum of two values. Read more
impl<A: Ord + Clone + Debug> Debug for OrdSet<A>
[src]
impl<A: Ord + Clone + Debug> Debug for OrdSet<A>
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 | [src] |
fn hash_slice<H>(data: &[Self], state: &mut H) where | 1.3.0 [src] |
Feeds a slice of this type into the given [Hasher
]. Read more
impl<A: Ord + Clone> Add<OrdSet<A>> for OrdSet<A>
[src]
impl<A: Ord + Clone> Add<OrdSet<A>> for OrdSet<A>
type Output = OrdSet<A>
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output | [src] |
impl<'a, A: Ord + Clone> Add<&'a OrdSet<A>> for &'a OrdSet<A>
[src]
impl<'a, A: Ord + Clone> Add<&'a OrdSet<A>> for &'a OrdSet<A>
type Output = OrdSet<A>
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output | [src] |
impl<A: Ord + Clone> Mul<OrdSet<A>> for OrdSet<A>
[src]
impl<A: Ord + Clone> Mul<OrdSet<A>> for OrdSet<A>
type Output = OrdSet<A>
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self::Output | [src] |
impl<'a, A: Ord + Clone> Mul<&'a OrdSet<A>> for &'a OrdSet<A>
[src]
impl<'a, A: Ord + Clone> Mul<&'a OrdSet<A>> for &'a OrdSet<A>
type Output = OrdSet<A>
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self::Output | [src] |
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 | [src] |
impl<A: Ord + Clone> Sum<OrdSet<A>> for OrdSet<A>
[src]
impl<A: Ord + Clone> Sum<OrdSet<A>> for OrdSet<A>
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<I> IntoIterator for I where
I: Iterator,
[src]
impl<I> IntoIterator for I where
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I | [src] |
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> | [src] |
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |
impl<T> Same for T
[src]
impl<T> Same for T
type Output = T
Should always be Self