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 standard library.
std › compress › zstd › Decompress › Table › decode Public Function decode Doc Source Public Function std.compress.zstd.Decompress.Table.decode
pub fn decode (
bit_reader : *BitReader ,
expected_symbol_count : usize ,
max_accuracy_log : u4 ,
entries : []Table .Fse ,
) !usize Params bit_reader : *BitReader expected_symbol_count : usize max_accuracy_log : u4 entries : []Table .Fse File compress/zstd/Decompress.zig: 1426
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488 pub fn decode (
bit_reader : *BitReader ,
expected_symbol_count : usize ,
max_accuracy_log : u4 ,
entries : []Table .Fse ,
) !usize {
const accuracy_log_biased = try bit_reader .readBitsNoEof (u4 , 4 );
if (accuracy_log_biased > max_accuracy_log -| 5 ) return error .MalformedAccuracyLog ;
const accuracy_log = accuracy_log_biased + 5 ;
var values : [256 ]u16 = undefined ;
var value_count : usize = 0 ;
const total_probability = @as (u16 , 1 ) << accuracy_log ;
var accumulated_probability : u16 = 0 ;
while (accumulated_probability < total_probability ) {
// WARNING: The RFC is poorly worded, and would suggest std.math.log2_int_ceil is correct here,
// but power of two (remaining probabilities + 1) need max bits set to 1 more.
const max_bits = std .math .log2_int (u16 , total_probability - accumulated_probability + 1 ) + 1 ;
const small = try bit_reader .readBitsNoEof (u16 , max_bits - 1 );
const cutoff = (@as (u16 , 1 ) << max_bits ) - 1 - (total_probability - accumulated_probability + 1 );
const value = if (small < cutoff )
small
else value : {
const value_read = small + (try bit_reader .readBitsNoEof (u16 , 1 ) << (max_bits - 1 ));
break :value if (value_read < @as (u16 , 1 ) << (max_bits - 1 ))
value_read
else
value_read - cutoff ;
};
accumulated_probability += if (value != 0 ) value - 1 else 1 ;
values [value_count ] = value ;
value_count += 1 ;
if (value == 1 ) {
while (true ) {
const repeat_flag = try bit_reader .readBitsNoEof (u2 , 2 );
if (repeat_flag + value_count > 256 ) return error .MalformedFseTable ;
for (0 ..repeat_flag ) |_ | {
values [value_count ] = 1 ;
value_count += 1 ;
}
if (repeat_flag < 3 ) break ;
}
}
if (value_count == 256 ) break ;
}
bit_reader .alignToByte ();
if (value_count < 2 ) return error .MalformedFseTable ;
if (accumulated_probability != total_probability ) return error .MalformedFseTable ;
if (value_count > expected_symbol_count ) return error .MalformedFseTable ;
const table_size = total_probability ;
try build (values [0 ..value_count ], entries [0 ..table_size ]);
return table_size ;
}