Nuria Framework - Core
Core module of the NuriaProject Framework
 All Classes Functions Typedefs Enumerations Enumerator Groups
essentials.hpp
1 /* Copyright (c) 2014, The Nuria Project
2  * This software is provided 'as-is', without any express or implied
3  * warranty. In no event will the authors be held liable for any damages
4  * arising from the use of this software.
5  * Permission is granted to anyone to use this software for any purpose,
6  * including commercial applications, and to alter it and redistribute it
7  * freely, subject to the following restrictions:
8  * 1. The origin of this software must not be misrepresented; you must not
9  * claim that you wrote the original software. If you use this software
10  * in a product, an acknowledgment in the product documentation would be
11  * appreciated but is not required.
12  * 2. Altered source versions must be plainly marked as such, and must not be
13  * misrepresented as being the original software.
14  * 3. This notice may not be removed or altered from any source
15  * distribution.
16  */
17 
18 #ifndef NURIA_ESSENTIALS_HPP
19 #define NURIA_ESSENTIALS_HPP
20 
21 #include "core_global.hpp"
22 #include <cstdint>
23 
24 namespace Nuria {
25 
27 constexpr uint32_t jenkinsOne (uint32_t hash, const char *key, int len) {
28  return (len < 1)
29  ? hash
30  : jenkinsOne ((hash + *key + ((hash + *key) << 10)) ^
31  ((hash + *key + ((hash + *key) << 10)) >> 6),
32  key + 1, len - 1);
33 }
34 
45 constexpr uint32_t jenkinsHash (const char *key, size_t len) {
46  return ((jenkinsOne (0, key, len) + (jenkinsOne (0, key, len) << 3)) ^
47  ((jenkinsOne (0, key, len) + (jenkinsOne (0, key, len) << 3)) >> 11)) +
48  (((jenkinsOne (0, key, len) + (jenkinsOne (0, key, len) << 3)) ^
49  ((jenkinsOne (0, key, len) + (jenkinsOne (0, key, len) << 3)) >> 11)) << 15);
50 }
51 
52 }
53 
54 #endif // NURIA_ESSENTIALS_HPP