Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

collapseRepeatsLen

Public Function
std.mem.collapseRepeatsLen
pub fn collapseRepeatsLen(comptime T: type, slice: []T, elem: T) usize

Collapse consecutive duplicate elements into one entry.

Params

  • T: type
  • slice: []T
  • elem: T

File

mem.zig:4159
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
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;
}