Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
hash-combine.hpp
Go to the documentation of this file.
1/*
2 HASH-COMBINE.hpp - hash chaining function extracted from LibBoost
3
4 Copyright (C)
5 2012, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12 ======================================================================
13 NOTE: this header adapts implementation code from LibBoost 1.67
14
15// Copyright 2005-2014 Daniel James.
16// Distributed under the Boost Software License, Version 1.0.
17// (See http://www.boost.org/LICENSE_1_0.txt)
18//
19// Based on Peter Dimov's proposal
20// http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
21// issue 6.18.
22//
23// This also contains public domain code from MurmurHash. From the MurmurHash header:
24//
25// MurmurHash3 was written by Austin Appleby, and is placed in the public
26// domain. The author hereby disclaims copyright to this source code.
27 ======================================================================
28*/
29
30
43#ifndef LIB_HASH_COMBINE_H
44#define LIB_HASH_COMBINE_H
45
46#include "lib/hash-value.h"
47#include "lib/integral.hpp"
48
49#include <climits>
50
51namespace lib {
52namespace hash{
53
59 inline void
60 combine (size_t & combinedHash, size_t additionalHash)
61 {
62#if false
63 combinedHash ^= additionalHash
64 + 0x9e3779b9
65 + (combinedHash<<6)
66 + (combinedHash>>2);
67 }
68#endif
72 /*
73// Don't define 64-bit hash combine on platforms without 64 bit integers,
74// and also not for 32-bit gcc as it warns about the 64-bit constant.
75#if !defined(BOOST_NO_INT64_T) && \
76 !(defined(__GNUC__) && ULONG_MAX == 0xffffffff)
77
78 inline void hash_combine_impl(boost::uint64_t& h,
79 boost::uint64_t k)
80 {
81*/
82 static_assert (sizeof (void*) * CHAR_BIT == 64, "TODO 2024 : decide what to do about portability");
83 static_assert (sizeof (size_t) == sizeof(uint64_t));
84
85 uint64_t& h = combinedHash;
86 uint64_t k = additionalHash;
87
88 const uint64_t m{0xc6a4a7935bd1e995};
89 const int r = 47;
90
91 k *= m;
92 k ^= k >> r;
93 k *= m;
94
95 h ^= k;
96 h *= m;
97
98 // Completely arbitrary number, to prevent 0's
99 // from hashing to 0.
100 h += 0xe6546b64;
101 }
102
104 //
105 //
106 //
107}} // namespace lib::hash
108#endif /*LIB_HASH_COMBINE_H*/
#define hash
Hash value types and utilities.
Inclusion for common place integral types and constants.
void combine(size_t &combinedHash, size_t additionalHash)
meld the additional hash value into the given base hash value.
Implementation namespace for support and library code.