Function iter_set::cmp [−][src]
pub fn cmp<T, L, R>(a: L, b: R) -> Option<Ordering> where
T: Ord,
L: IntoIterator<Item = T>,
R: IntoIterator<Item = T>,
Expand description
Compare two sets represented by sorted, deduplicated iterators.
The return value represents a partial ordering based on set inclusion. If the iterators
are equal, then Some(Equal)
is returned. If a
is a subset of b
then Some(Less)
is returned. If a
is a superset of b
then Some(Greater)
is returned. Otherwise,
None
is returned. If a
and b
are not sorted or contain duplicate values, the return
value is unspecified.
Time complexity: O(a.len() + b.len())
.
Examples
use std::cmp::Ordering::{Equal, Greater, Less};
use iter_set::cmp;
let a = [1, 2, 3];
let b = [2, 3];
let c = [2, 3, 4];
assert_eq!(cmp(&a, &b), Some(Greater));
assert_eq!(cmp(&b, &b), Some(Equal));
assert_eq!(cmp(&b, &c), Some(Less));
assert_eq!(cmp(&a, &c), None);