1 //  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 #pragma once
7 
8 #include <cstdint>
9 
10 namespace folly {
11 namespace hash {
12 
13 /*
14  * Thomas Wang 64 bit mix hash function
15  */
16 
twang_mix64(uint64_t key)17 inline uint64_t twang_mix64(uint64_t key) noexcept {
18   key = (~key) + (key << 21); // key *= (1 << 21) - 1; key -= 1;
19   key = key ^ (key >> 24);
20   key = key + (key << 3) + (key << 8); // key *= 1 + (1 << 3) + (1 << 8)
21   key = key ^ (key >> 14);
22   key = key + (key << 2) + (key << 4); // key *= 1 + (1 << 2) + (1 << 4)
23   key = key ^ (key >> 28);
24   key = key + (key << 31); // key *= 1 + (1 << 31)
25   return key;
26 }
27 
28 } // namespace hash
29 } // namespace folly
30