Trait ckb_rust_unstable_port::IsSorted [−][src]
Extends Iterator
with is_sorted
, is_sorted_by
, and
is_sorted_by_key
.
Provided methods
pub fn is_sorted(&mut self) -> bool where
Self::Item: PartialOrd<Self::Item>,
[src]
Self::Item: PartialOrd<Self::Item>,
Returns true
if the elements of the iterator are sorted in increasing
order according to <Self::Item as PartialOrd>::partial_cmp
.
let v = vec![0, 1, 2, 3]; assert!(IsSorted::is_sorted(&mut v.iter())); let v = vec![0, 1, 2, -1]; assert!(!IsSorted::is_sorted(&mut v.iter()));
pub fn is_sorted_by<F>(&mut self, compare: F) -> bool where
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
[src]
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
Returns true
if the elements of the iterator
are sorted according to the compare
function.
// Is an iterator sorted in decreasing order? fn decr<T: PartialOrd>(a: &T, b: &T) -> Option<Ordering> { a.partial_cmp(b).map(|v| v.reverse()) } let v = vec![3, 2, 1, 0]; assert!(IsSorted::is_sorted_by(&mut v.iter(), decr)); let v = vec![3, 2, 1, 4]; assert!(!IsSorted::is_sorted_by(&mut v.iter(), decr));
pub fn is_sorted_by_key<F, B>(&mut self, key: F) -> bool where
B: PartialOrd<B>,
F: FnMut(&Self::Item) -> B,
[src]
B: PartialOrd<B>,
F: FnMut(&Self::Item) -> B,
Returns true
if the elements of the iterator
are sorted according to the key
extraction function.
let v = vec![0_i32, -1, 2, -3]; assert!(IsSorted::is_sorted_by_key(&mut v.iter(), |v| v.abs())); let v = vec![0_i32, -1, 2, 0]; assert!(!IsSorted::is_sorted_by_key(&mut v.iter(), |v| v.abs()));
pub fn is_sorted_until_by<F>(
self,
compare: F
) -> (Option<(Self::Item, Self::Item)>, Self) where
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
[src]
self,
compare: F
) -> (Option<(Self::Item, Self::Item)>, Self) where
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
Returns the first unsorted pair of items in the iterator and its tail.
let v: &[i32] = &[0, 1, 2, 3, 4, 1, 2, 3]; let (first, tail) = v.iter().is_sorted_until_by(|a, b| a.partial_cmp(b)); assert_eq!(first, Some((&4, &1))); assert_eq!(tail.as_slice(), &[2, 3]);