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

bytesWeightedWithHash

Public Function
std.testing.Smith.bytesWeightedWithHash
pub fn bytesWeightedWithHash(s: *Smith, out: []u8, weights: []const Weight, hash: u32) void

Params

File

testing/Smith.zig:571
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
pub fn bytesWeightedWithHash(s: *Smith, out: []u8, weights: []const Weight, hash: u32) void {
    @disableInstrumentation();
    checkWeights(weights, 255);

    if (s.in) |*in| {
        var present_weights: [256]bool = @splat(false);
        for (weights) |w| {
            @memset(present_weights[@intCast(w.min)..@intCast(w.max + 1)], true);
        }
        const default: u8 = @intCast(weights[0].min);

        const copy_len = @min(out.len, in.len);
        for (in.*[0..copy_len], out[0..copy_len]) |i, *o| {
            o.* = if (present_weights[i]) i else default;
        }
        in.* = in.*[copy_len..];
        @memset(out[copy_len..], default);
    } else if (builtin.fuzz) {
        @branchHint(.likely);
        fuzz_abi.fuzzer_bytes(bytesUid(hash), .fromSlice(out), .fromSlice(weights));
    } else unreachable;
}