DoxigAlpha

getAutoHashFn

Function parameters

Parameters

#
K:type
Context:type

Type definitions in this namespace

Types

#

Functions in this namespace

Functions

#
StringHashMap
Builtin hashmap for strings as keys.
StringHashMapUnmanaged
Key memory is managed by the caller.
HashMap
General purpose hash table.
HashMapUnmanaged
A HashMap based on open addressing and linear probing.

= 80

Values

#

Source

Implementation

#
pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K) u64) {
    comptime {
        assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated
        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;
}