slice-group-by
An implementation of the group_by
Haskell function for slices only.
Introduction
Crate slice-group-by
is a library for efficiently iterating over a slice by groups defined by a function that specifies if two elements are in the same group.
Example: Linear Searched Immutable Groups
You will only need to define a function that returns true
if two elements are in the same group.
The LinearGroupBy
iterator will always gives contiguous elements to the predicate tion.
use GroupBy;
let slice = &;
let mut iter = slice.linear_group_by;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Example: Binary Searched Mutable Groups
It is also possible to get mutable non overlapping groups of a slice.
The BinaryGroupBy/Mut
and ExponentialGroupBy/Mut
iterators will not necessarily
gives contiguous elements to the predicate function. The predicate function should ement
an order consistent with the sort order of the slice.
use GroupByMut;
let slice = &mut ;
let mut iter = slice.binary_group_by_mut;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Example: Exponential Searched Mutable Groups starting from the End
It is also possible to get mutable non overlapping groups of a slice even starting from end of the slice.
use GroupByMut;
let slice = &mut ;
let mut iter = slice.exponential_group_by_mut.rev;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;