Zig 0.17.0-dev (Split by item)
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 library itself.
Zig › std/ › compress/ › flate/ › Compress.zig › matchAndAddHash
matchAndAddHash
Compress.matchAndAddHash
fn matchAndAddHash (c : *Compress , i : usize , h : Hash , gt : u16 , max_chain : u16 , good_ : u16 ) struct
File
Code
fn matchAndAddHash (c : *Compress , i : usize , h : Hash , gt : u16 , max_chain : u16 , good_ : u16 ) struct {
dist : u16 ,
len : u16 ,
} {
const l = &c .lookup ;
const buffered = c .writer .buffered ();
var chain_limit = max_chain ;
var best_dist : u16 = undefined ;
var best_len = gt ;
const nice = @min (c .opts .nice , buffered [i ..].len );
var good = good_ ;
search : {
if (l .head [h ].is_null ) break :search ;
var dist : u16 = l .chain_pos -% l .head [h ].value ;
while (true ) {
chain_limit -= 1 ;
const match_len = betterMatchLen (best_len , buffered [i - 1 - dist ..], buffered [i ..]);
if (match_len > best_len ) {
best_dist = dist ;
best_len = match_len ;
if (best_len >= nice ) break ;
if (best_len >= good ) {
chain_limit >>= 2 ;
good = math .maxInt (u8 );
}
}
if (chain_limit == 0 ) break ;
const next_chain_index = l .chain_pos -% @as (u15 , @intCast (dist ));
// if (l.chain[next_chain_index].is_null) break;
// dist, const out_of_window = @addWithOverflow(dist, l.chain[next_chain_index].value);
// if (out_of_window == 1) break;
dist +%= l .chain [next_chain_index ].int ();
comptime assert (flate .history_len == PackedOptionalU15 .int (.null_bit ));
if ((dist | l .chain [next_chain_index ].int ()) & flate .history_len != 0 ) break ;
}
}
c .addHash (i , h );
return .{ .dist = best_dist , .len = best_len };
}