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. Private Function

checkWeights

Private Function
std.testing.Smith.checkWeights
fn checkWeights(weights: []const Weight, max_incl: u64) void

Params

  • weights: []const Weight
  • max_incl: u64

File

testing/Smith.zig:177
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
fn checkWeights(weights: []const Weight, max_incl: u64) void {
    @disableInstrumentation();
    const w0 = weights[0]; // Sum of weights is zero
    assert(w0.weight != 0);
    assert(w0.max <= max_incl);

    var incl_sum: u64 = (w0.max - w0.min) * w0.weight + (w0.weight - 1); // Sum of weights greater than 2^64
    for (weights[1..]) |w| {
        assert(w.weight != 0);
        assert(w.max <= max_incl);
        // This addition will not overflow except with an illegal combination of weights since
        // the exclusive sum must be at least one so a span of all values is impossible.
        incl_sum += (w.max - w.min + 1) * w.weight; // Sum of weights greater than 2^64
    }
}