TrinityCore
Hash.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TrinityCore_Hash_h__
19#define TrinityCore_Hash_h__
20
21#include <functional>
22#include <string_view>
23#include <utility>
24
25namespace Trinity
26{
27 template<typename T>
28 inline void hash_combine(std::size_t& seed, T const& val)
29 {
30 seed ^= std::hash<T>()(val) + 0x9E3779B9 + (seed << 6) + (seed >> 2);
31 }
32
33 inline std::uint32_t HashFnv1a(std::string_view data)
34 {
35 std::uint32_t hash = 0x811C9DC5u;
36 for (char c : data)
37 {
38 hash ^= c;
39 hash *= 0x1000193u;
40 }
41 return hash;
42 }
43}
44
47template<class K, class V>
48struct std::hash<std::pair<K, V>>
49{
50public:
51 size_t operator()(std::pair<K, V> const& p) const
52 {
53 size_t hashVal = 0;
54 Trinity::hash_combine(hashVal, p.first);
55 Trinity::hash_combine(hashVal, p.second);
56 return hashVal;
57 }
58};
59
60#endif // TrinityCore_Hash_h__
void hash_combine(std::size_t &seed, T const &val)
Definition: Hash.h:28
std::uint32_t HashFnv1a(std::string_view data)
Definition: Hash.h:33
STL namespace.
size_t operator()(std::pair< K, V > const &p) const
Definition: Hash.h:51