BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Hash.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12
13#ifndef CL_HASH_HPP
14#define CL_HASH_HPP
15
16#include <functional>
17#include <cstddef>
18#include "typedefs.hpp"
19
20namespace belfem
21{
28 class Hash
29 {
30 std::size_t mValue = 0 ;
31
32//------------------------------------------------------------------------------
33 public:
34//------------------------------------------------------------------------------
35
36 Hash() = default ;
37
38//------------------------------------------------------------------------------
39
40 ~Hash() = default ;
41
42//------------------------------------------------------------------------------
43
44 inline void
46 {
47 mValue = 0 ;
48 }
49
50//------------------------------------------------------------------------------
51
52 inline std::size_t
53 value() const
54 {
55 return mValue;
56 }
57
58//------------------------------------------------------------------------------
59
60 inline void
61 set_value( const std::size_t aValue )
62 {
63 mValue = aValue ;
64 }
65
66//------------------------------------------------------------------------------
67
68 template< typename T >
69 Hash &
70 operator += ( const T aValue )
71 {
72 mValue +=
73 // Compute and add the hash of the new value.
74 std::hash<T>{}(aValue)
75 // Add an entropy constant (derived from the golden ratio) for better distribution.
76 + 0x9e3779b97f4a7c15ULL
77 // Mix in the current hash by shifting left (emphasizes high-order bits).
78 + (mValue << 6)
79 // Mix in the current hash by shifting right (brings in low-order bits).
80 + (mValue >> 2);
81
82 return *this;
83 }
84
85//------------------------------------------------------------------------------
86 };
87//------------------------------------------------------------------------------
88}
89#endif //CL_HASH_HPP
Incremental hash computation.
Definition cl_Hash.hpp:29
~Hash()=default
void reset()
Definition cl_Hash.hpp:45
Hash & operator+=(const T aValue)
Definition cl_Hash.hpp:70
std::size_t value() const
Definition cl_Hash.hpp:53
Hash()=default
void set_value(const std::size_t aValue)
Definition cl_Hash.hpp:61
USER GUIDES:
Definition cl_Capacitor.cpp:16