slice_group_by/linear_group/linear_group.rs
1use crate::{LinearGroupBy, LinearGroupByMut};
2
3/// An iterator that will return non-overlapping groups of equal elements
4/// in the slice using *linear/sequential search*.
5///
6/// It will give two contiguous elements to the [`PartialEq::eq`] function
7/// therefore the slice must not be necessarily sorted.
8///
9/// [`PartialEq::eq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#tymethod.eq
10pub struct LinearGroup<'a, T: 'a>(LinearGroupBy<'a, T, fn(&T, &T) -> bool>);
11
12impl<'a, T: 'a> LinearGroup<'a, T>
13where T: PartialEq,
14{
15 pub fn new(slice: &'a [T]) -> LinearGroup<'a, T> {
16 LinearGroup(LinearGroupBy::new(slice, PartialEq::eq))
17 }
18}
19
20group_by_wrapped!{ struct LinearGroup, &'a [T] }
21
22/// An iterator that will return non-overlapping *mutable* groups of equal elements
23/// in the slice using *linear/sequential search*.
24///
25/// It will give two contiguous elements to the [`PartialEq::eq`] function
26/// therefore the slice must not be necessarily sorted.
27///
28/// [`PartialEq::eq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#tymethod.eq
29pub struct LinearGroupMut<'a, T: 'a>(LinearGroupByMut<'a, T, fn(&T, &T) -> bool>);
30
31impl<'a, T: 'a> LinearGroupMut<'a, T>
32where T: PartialEq,
33{
34 pub fn new(slice: &'a mut [T]) -> LinearGroupMut<'a, T> {
35 LinearGroupMut(LinearGroupByMut::new(slice, PartialEq::eq))
36 }
37}
38
39group_by_wrapped!{ struct LinearGroupMut, &'a mut [T] }