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 › hash_map › Custom › grow Private Function grow Doc Source Private Function std.hash_map.Custom.grow
fn grow (self : *Self , allocator : Allocator , new_capacity : Size , ctx : Context ) Allocator .Error !void Params File hash_map.zig: 1428
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 fn grow (self : *Self , allocator : Allocator , new_capacity : Size , ctx : Context ) Allocator .Error !void {
@branchHint (.cold );
const new_cap = @max (new_capacity , minimal_capacity );
assert (new_cap > self .capacity ());
assert (std .math .isPowerOfTwo (new_cap ));
var map : Self = .{};
try map .allocate (allocator , new_cap );
errdefer comptime unreachable ;
map .pointer_stability .lock ();
map .initMetadatas ();
map .available = @truncate ((new_cap * max_load_percentage ) / 100 );
if (self .size != 0 ) {
const old_capacity = self .capacity ();
for (
self .metadata .?[0 ..old_capacity ],
self .keys ()[0 ..old_capacity ],
self .values ()[0 ..old_capacity ],
) |m , k , v | {
if (!m .isUsed ()) continue ;
map .putAssumeCapacityNoClobberContext (k , v , ctx );
if (map .size == self .size ) break ;
}
}
self .size = 0 ;
self .pointer_stability = .{};
std .mem .swap (Self , self , &map );
map .deinit (allocator );
}