Function collapseRepeatsLen [src]
Collapse consecutive duplicate elements into one entry.
Prototype
pub fn collapseRepeatsLen(comptime T: type, slice: []T, elem: T) usize
Parameters
T: type
slice: []T
elem: T
Source
pub fn collapseRepeatsLen(comptime T: type, slice: []T, elem: T) usize {
if (slice.len == 0) return 0;
var write_idx: usize = 1;
var read_idx: usize = 1;
while (read_idx < slice.len) : (read_idx += 1) {
if (slice[read_idx - 1] != elem or slice[read_idx] != elem) {
slice[write_idx] = slice[read_idx];
write_idx += 1;
}
}
return write_idx;
}