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 › getOrPutContextAdapted Public Function getOrPutContextAdapted Doc Source Public Function std.hash_map.Custom.getOrPutContextAdapted
pub fn getOrPutContextAdapted (self : *Self , allocator : Allocator , key : anytype , key_ctx : anytype , ctx : Context ) Allocator .Error !GetOrPutResult Params File hash_map.zig: 1112
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129 pub fn getOrPutContextAdapted (self : *Self , allocator : Allocator , key : anytype , key_ctx : anytype , ctx : Context ) Allocator .Error !GetOrPutResult {
{
self .pointer_stability .lock ();
defer self .pointer_stability .unlock ();
self .growIfNeeded (allocator , 1 , ctx ) catch |err | {
// If allocation fails, try to do the lookup anyway.
// If we find an existing item, we can return it.
// Otherwise return the error, we could not add another.
const index = self .getIndex (key , key_ctx ) orelse return err ;
return GetOrPutResult {
.key_ptr = &self .keys ()[index ],
.value_ptr = &self .values ()[index ],
.found_existing = true ,
};
};
}
return self .getOrPutAssumeCapacityAdapted (key , key_ctx );
}