Hashing function for numbers
This commit is contained in:
parent
1d53ad9435
commit
0818896cb6
1 changed files with 12 additions and 0 deletions
|
|
@ -76,3 +76,15 @@ constexpr uint64_t hashNoAmpersand(absl::string_view s, uint64_t h = Fnv1aBasis)
|
|||
: hashNoAmpersand( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Run-time hashing function for numbers, useful for example to
|
||||
* create hash functions for keys which depend on numeric values.
|
||||
*/
|
||||
template <class Int>
|
||||
uint64_t hashNumber(Int i, uint64_t h = Fnv1aBasis)
|
||||
{
|
||||
static_assert(std::is_arithmetic<Int>::value,
|
||||
"The hashed object must be of arithmetic type");
|
||||
return hash(absl::string_view(reinterpret_cast<const char*>(&i), sizeof(i)), h);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue