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

indexOfDiff

Public Function
std.mem.indexOfDiff
pub fn findDiff(comptime T: type, a: []const T, b: []const T) ?usize

Compares two slices and returns the index of the first inequality. Returns null if the slices are equal.

Params

  • T: type
  • a: []const T
  • b: []const T

File

mem.zig:858
858
859
860
861
862
863
864
865
866
867
pub fn findDiff(comptime T: type, a: []const T, b: []const T) ?usize {
    const shorter = @min(a.len, b.len);
    if (@typeInfo(T) != .float and a.ptr == b.ptr) {
        return if (a.len == b.len) null else shorter;
    }
    for (a[0..shorter], b[0..shorter], 0..) |a_elem, b_elem, i| {
        if (a_elem != b_elem) return i;
    }
    return if (a.len == b.len) null else shorter;
}