forked from foonathan/string_id
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.hpp
31 lines (24 loc) · 1.01 KB
/
hash.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (C) 2014-2015 Jonathan Müller <[email protected]>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#ifndef FOONATHAN_STRING_ID_HASH_HPP_INCLUDED
#define FOONATHAN_STRING_ID_HASH_HPP_INCLUDED
#include <cstdint>
#include "config.hpp"
namespace foonathan { namespace string_id
{
/// \brief The type of a hashed string.
/// \detail This is an unsigned integral type.
typedef std::uint64_t hash_type;
namespace detail
{
FOONATHAN_CONSTEXPR hash_type fnv_basis = 14695981039346656037ull;
FOONATHAN_CONSTEXPR hash_type fnv_prime = 1099511628211ull;
// FNV-1a 64 bit hash
FOONATHAN_CONSTEXPR_FNC hash_type sid_hash(const char *str, hash_type hash = fnv_basis)
{
return *str ? sid_hash(str + 1, (hash ^ *str) * fnv_prime) : hash;
}
} // namespace detail
}} // foonathan::string_id
#endif // FOONATHAN_STRING_ID_DETAIL_HASH_HPP_INCLUDED