constexpr hash compatible with c++11
This commit is contained in:
parent
8861e0e8dc
commit
17f6967509
1 changed files with 6 additions and 12 deletions
|
|
@ -56,10 +56,7 @@ constexpr uint64_t Fnv1aPrime = 0x01000193;
|
|||
*/
|
||||
constexpr uint64_t hash(absl::string_view s, uint64_t h = Fnv1aBasis)
|
||||
{
|
||||
if (s.length() > 0)
|
||||
return hash( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime );
|
||||
|
||||
return h;
|
||||
return (s.length() == 0) ? h : hash( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -73,12 +70,9 @@ constexpr uint64_t hash(absl::string_view s, uint64_t h = Fnv1aBasis)
|
|||
*/
|
||||
constexpr uint64_t hashNoAmpersand(absl::string_view s, uint64_t h = Fnv1aBasis)
|
||||
{
|
||||
if (s.length() > 0) {
|
||||
if (s.front() == '&')
|
||||
return hashNoAmpersand( { s.data() + 1, s.length() - 1 }, h );
|
||||
else
|
||||
return hashNoAmpersand( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime );
|
||||
}
|
||||
|
||||
return h;
|
||||
return (s.length() == 0) ? h : (
|
||||
(s.front() == '&')
|
||||
? hashNoAmpersand( { s.data() + 1, s.length() - 1 }, h )
|
||||
: hashNoAmpersand( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime )
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue