Function hash

Takes an argument of an arbitrary type T and calculates the hash value.

size_t hash(T) (
  auto ref T key
);

Hash calculation is supported for all scalar types. Aggregate types, like structs, should implement toHash-function:

size_t toHash() const
{
 return hash;
}

For pointers and for scalar types implicitly convertible to size_t this is an identity operation (i.e. the value is cast to size_t and returned unaltered). Integer types wider than size_t are XOR folded down to size_t. Other scalar types use an architecture-dependent hash function based on their width and alignment. If the type provides a toHash-function, only toHash() is called and its result is returned.

This function also accepts input ranges that contain hashable elements. Individual values are combined then and the resulting hash is returned.

Parameters

NameDescription
T Hashable type.
key Hashable value.

Returns

Calculated hash value.

See Also

http://www.isthe.com/chongo/tech/comp/fnv/.