Celeritas
0.5.0-86+4a8eea4
|
#include <cstddef>
#include <functional>
#include <initializer_list>
#include <type_traits>
#include "corecel/Macros.hh"
#include "corecel/cont/Span.hh"
#include "detail/FnvHasher.hh"
Typedefs | |
using | celeritas::Hasher = detail::FnvHasher< std::size_t > |
Functions | |
template<class T , std::size_t N> | |
std::size_t | celeritas::hash_as_bytes (Span< T const, N > s) |
Hash a span of contiguous data without padding. More... | |
template<class... Args> | |
std::size_t | celeritas::hash_combine (Args const &... args) |
Combine hashes of the given arguments using a fast hash algorithm. More... | |
std::size_t celeritas::hash_as_bytes | ( | Span< T const, N > | s | ) |
Hash a span of contiguous data without padding.
This should generally only be used if has_unique_object_representations_v
is true
, because e.g. structs have padding so this may result in reading uninitialized data or giving two equal structs different hashes.
std::size_t celeritas::hash_combine | ( | Args const &... | args | ) |
Combine hashes of the given arguments using a fast hash algorithm.
See https://florianjw.de/en/variadic_templates.html for why we constructed this as such. By making the variadic template use function argument expansion rather than recursion, we can unpack the args in a left-to-right order. The (HASH,0)
construction is to give the unpacked expression a return type; and putting these in an initializer_list
constructor guarantees the hashes are evaluated from left to right (unlike a typical argument expansion where the orders may be arbitrary).