slice_group_by/exponential_group/
exponential_group.rs

1use crate::{ExponentialGroupBy, ExponentialGroupByMut};
2
3/// An iterator that will return non-overlapping groups of equal elements, according to
4/// the [`PartialEq::eq`] function in the slice using *exponential search*.
5///
6/// It will not necessarily gives contiguous elements to the predicate function.
7/// The predicate function should implement an order consistent with the sort order of the slice.
8///
9/// [`PartialEq::eq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#tymethod.eq
10pub struct ExponentialGroup<'a, T: 'a>(ExponentialGroupBy<'a, T, fn(&T, &T) -> bool>);
11
12impl<'a, T: 'a> ExponentialGroup<'a, T>
13where T: PartialEq,
14{
15    pub fn new(slice: &'a [T]) -> ExponentialGroup<'a, T> {
16        ExponentialGroup(ExponentialGroupBy::new(slice, PartialEq::eq))
17    }
18}
19
20group_by_wrapped!{ struct ExponentialGroup, &'a [T] }
21
22/// An iterator that will return non-overlapping *mutable* groups of equal elements, according to
23/// the [`PartialEq::eq`] function in the slice using *exponential search*.
24///
25/// It will not necessarily gives contiguous elements to the predicate function.
26/// The predicate function should implement an order consistent with the sort order of the slice.
27///
28/// [`PartialEq::eq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#tymethod.eq
29pub struct ExponentialGroupMut<'a, T: 'a>(ExponentialGroupByMut<'a, T, fn(&T, &T) -> bool>);
30
31impl<'a, T: 'a> ExponentialGroupMut<'a, T>
32where T: PartialEq,
33{
34    pub fn new(slice: &'a mut [T]) -> ExponentialGroupMut<'a, T> {
35        ExponentialGroupMut(ExponentialGroupByMut::new(slice, PartialEq::eq))
36    }
37}
38
39group_by_wrapped!{ struct ExponentialGroupMut, &'a mut [T] }