hash_utils.hpp

This file provides tools for hashing values and containers.

Note

Status: BETA

Functions

template<typename T>
std::size_t Hash(const T &x) noexcept
inline uint64_t szudzik_hash(uint32_t a_, uint32_t b_) noexcept

Generate a unique long from a pair of ints.

Parameters:
  • a_ – First 32-bit unsigned int.

  • b_ – Second 32-bit unsigned int.

Returns:

64-bit unsigned int representing the szudzik hash of both inputs.

inline constexpr std::size_t hash_combine(std::size_t hash1) noexcept

If hash_combine has a single value, there’s nothing to combine; just return it!

inline constexpr std::size_t hash_combine(std::size_t hash1, std::size_t hash2) noexcept

Boost’s implementation of a simple hash-combining function. Taken from https://www.boost.org/doc/libs/1_37_0/doc/html/hash/reference.html#boost.hash_combine

Parameters:
  • hash1 – First hash to combine.

  • hash2 – Second hash to combine.

Returns:

Combined hash.

template<typename ...Ts>
inline constexpr std::size_t hash_combine(std::size_t hash1, std::size_t hash2, std::size_t hash3, Ts... extras) noexcept

Allow hash_combine to work with more than two input values.

inline std::size_t hash_combine(Ptr<const std::size_t> hashes, size_t num_hashes) noexcept

Allow hash_combine to take a series of size_t’s to merge into a single hash.

template<typename ...Ts>
inline std::size_t CombineHash(const Ts&... args)

Alias hash_combine() to CombineHash()

inline constexpr uint64_t murmur_hash(const std::span<const std::byte> key, const uint64_t seed = 0) noexcept

Implementation of the murmur3 hash, a fast hash with low collisions. This hash makes it suitable for hash-based lookups. For more info, see: https://en.wikipedia.org/wiki/MurmurHash This implementation was directly based on: https://github.com/aappleby/smhasher/blob/92cf3702fcfaadc84eb7bef59825a23e0cd84f56/src/MurmurHash3.cpp

Parameters:
  • key – Span of bytes to hash.

  • seed – Optional seed.

Returns:

Hash of key.

template<typename Container, size_t Seed = 0>
struct ContainerHash
#include <hash_utils.hpp>

This structure serves as a hash for containers that are iterable. Use as a drop-in replacement for std::hash.

Public Functions

inline size_t operator()(const Container &v) const