KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
fnv_1a_hash.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license:
9 // kratos/license.txt
10 //
11 // Main authors: Pooyan Dadvand
12 // Vicente Mataix Ferrandiz
13 //
14 //
15 
16 #if !defined(KRATOS_FNV_1A_HASH_H_INCLUDED)
17 #define KRATOS_FNV_1A_HASH_H_INCLUDED
18 
19 namespace Kratos {
24 
34 class FNV1a32Hash {
35 
36 public:
39 
41  typedef std::uint32_t HashType;
42 
46 
48  FNV1a32Hash() = delete;
49 
51  virtual ~FNV1a32Hash() = delete;
52 
54  FNV1a32Hash &operator=(FNV1a32Hash const &rOther) = delete;
55 
57  FNV1a32Hash(FNV1a32Hash const &rOther) = delete;
58 
62 
63  static constexpr HashType CalculateHash(const char *const TheString) {
64  return CalculateHash(mFNV32OfsetBasis, TheString);
65  }
66 
68 
69  private:
72 
73  static constexpr HashType mFNV32OfsetBasis = 0x811c9dc5;
74  static constexpr HashType mFNV32Prime = 0x1000193;
75 
79  static constexpr HashType CalculateHash(const HashType Value,
80  const char *const TheString) {
81  return (TheString[0] == '\0')
82  ? Value
83  : CalculateHash((Value ^ static_cast<HashType>(TheString[0])) * mFNV32Prime,
84  TheString + 1);
85  }
86 
88 
89 }; // Class FNV1a32Hash
90 
100 class FNV1a64Hash {
101 
102 public:
105 
107  typedef std::uint64_t HashType;
108 
112 
114  FNV1a64Hash() = delete;
115 
117  virtual ~FNV1a64Hash() = delete;
118 
120  FNV1a64Hash &operator=(FNV1a64Hash const &rOther) = delete;
121 
123  FNV1a64Hash(FNV1a64Hash const &rOther) = delete;
124 
128 
129  static constexpr HashType CalculateHash(const char *const TheString) {
130  return CalculateHash(mFNV64OfsetBasis, TheString);
131  }
132 
134 
135  private:
138 
139  static constexpr HashType mFNV64OfsetBasis = 0xcbf29ce484222325;
140  static constexpr HashType mFNV64Prime = 0x100000001b3;
141 
145  static constexpr HashType CalculateHash(const HashType Value,
146  const char *const TheString) {
147  return (TheString[0] == '\0')
148  ? Value
149  : CalculateHash((Value ^ static_cast<HashType>(TheString[0])) * mFNV64Prime,
150  TheString + 1);
151  }
152 
154 
155 }; // Class FNV1a64Hash
156 
158 
160 
161 } // namespace Kratos.
162 
163 #endif // KRATOS_FNV_1A_HASH_H_INCLUDED defined
A constexpr version of FNV hash function. (32 bit version)
Definition: fnv_1a_hash.h:34
FNV1a32Hash(FNV1a32Hash const &rOther)=delete
Copy constructor.
FNV1a32Hash()=delete
The class is unconstructable.
FNV1a32Hash & operator=(FNV1a32Hash const &rOther)=delete
Assignment operator.
static constexpr HashType CalculateHash(const char *const TheString)
Definition: fnv_1a_hash.h:63
std::uint32_t HashType
The hash to be employed is 32 bits this time.
Definition: fnv_1a_hash.h:41
virtual ~FNV1a32Hash()=delete
Destructor.
A constexpr version of FNV hash function. (64 bit version)
Definition: fnv_1a_hash.h:100
FNV1a64Hash()=delete
The class is unconstructable.
std::uint64_t HashType
The hash to be employed is 64 bits this time.
Definition: fnv_1a_hash.h:107
FNV1a64Hash & operator=(FNV1a64Hash const &rOther)=delete
Assignment operator.
FNV1a64Hash(FNV1a64Hash const &rOther)=delete
Copy constructor.
virtual ~FNV1a64Hash()=delete
Destructor.
static constexpr HashType CalculateHash(const char *const TheString)
Definition: fnv_1a_hash.h:129
std::size_t HashType
The definition of the hash type.
Definition: key_hash.h:38
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21