Celeritas  0.5.0-56+6b053cd
Typedefs | Functions
HashUtils.hh File Reference
#include <cstddef>
#include <functional>
#include <initializer_list>
#include <type_traits>
#include "corecel/Macros.hh"
#include "corecel/cont/Span.hh"
#include "detail/FnvHasher.hh"
This graph shows which files directly or indirectly include this file:

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...
 

Function Documentation

◆ hash_as_bytes()

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.

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.

◆ hash_combine()

template<class... Args>
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).