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/ › hash_map.zig › getAutoHashFn
getAutoHashFn
hash_map.getAutoHashFn
pub fn getAutoHashFn (comptime K : type , comptime Context : type ) (fn (Context , K ) u64 )
File
Code
pub fn getAutoHashFn (comptime K : type , comptime Context : type ) (fn (Context , K ) u64 ) {
comptime {
assert (@hasDecl (std , "StringHashMap" ));
if (K == []const u8 ) {
@compileError ("std.hash.autoHash does not allow slices here (" ++
@typeName (K ) ++
") because the intent is unclear. " ++
"Consider using std.StringHashMap for hashing the contents of []const u8. " ++
"Alternatively, consider using std.hash.autoHashStrat or providing your own hash function instead." );
}
}
return struct {
fn hash (ctx : Context , key : K ) u64 {
_ = ctx ;
if (std .meta .hasUniqueRepresentation (K )) {
return Wyhash .hash (0 , std .mem .asBytes (&key ));
} else {
var hasher = Wyhash .init (0 );
autoHash (&hasher , key );
return hasher .final ();
}
}
}.hash ;
}