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 Type Function

buildClen

Private Type Function
std.compress.flate.Compress.buildClen
fn buildClen(
    dyn_bits: []const u4,
    out_values: []u8,
    out_extra: []u8,
    out_freqs: *[19]u16,
) struct

Returns the number of values followed by the bitsize of the extra bits.

File

compress/flate/Compress.zig:772
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
fn buildClen(
    dyn_bits: []const u4,
    out_values: []u8,
    out_extra: []u8,
    out_freqs: *[19]u16,
) struct { u16, u16 } {
    assert(dyn_bits.len <= out_values.len);
    assert(out_values.len == out_extra.len);

    var len: u16 = 0;
    var extra_bitsize: u16 = 0;

    var remaining_bits = dyn_bits;
    var prev: u4 = 0;
    while (true) {
        const b = remaining_bits[0];
        const n_max = @min(@as(u8, if (b != 0)
            if (b != prev) 1 else 6
        else
            138), remaining_bits.len);
        prev = b;

        var n: u8 = 0;
        while (true) {
            remaining_bits = remaining_bits[1..];
            n += 1;
            if (n == n_max or remaining_bits[0] != b) break;
        }
        const code, const extra, const xsize = switch (n) {
            0 => unreachable,
            1...2 => .{ b, 0, 0 },
            3...10 => .{
                @as(u8, 16) + @intFromBool(b == 0),
                n - 3,
                @as(u8, 2) + @intFromBool(b == 0),
            },
            11...138 => .{ 18, n - 11, 7 },
            else => unreachable,
        };
        while (true) {
            out_values[len] = code;
            out_extra[len] = extra;
            out_freqs[code] += 1;
            extra_bitsize += xsize;
            len += 1;
            if (n != 2) {
                @branchHint(.likely);
                break;
            }
            // Code needs outputted once more
            n = 1;
        }
        if (remaining_bits.len == 0) break;
    }

    return .{ len, extra_bitsize };
}