1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Hash function class for primitives. All non-primitives used to hash
29 entries on hash tables likely need a specialized version of this class.
31 \*---------------------------------------------------------------------------*/
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 /*---------------------------------------------------------------------------*\
49 Class Hash Declaration
50 \*---------------------------------------------------------------------------*/
52 template<class PrimitiveType>
60 unsigned operator()(const PrimitiveType& p, unsigned seed) const
62 return Hasher(&p, sizeof(p), seed);
65 unsigned operator()(const PrimitiveType& p) const
67 return Hasher(&p, sizeof(p));
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 //- Hash specialization for hashing labels
84 //- Incrementally hash a label.
85 // This will necessarily return a different value than the
86 // non-incremental version.
87 unsigned operator()(const label& p, unsigned seed) const
89 return Hasher(&p, sizeof(label), seed);
92 //- Return the unsigned representation of a label.
93 // This helps if people have relied on the hash value corresponding to
95 unsigned operator()(const label& p) const
102 //- Hash specialization for hashing pointer addresses.
103 // Treat a pointer like a intptr_t.
104 // This should work for both 32-bit and 64-bit pointers.
113 unsigned operator()(const void* const& p, unsigned seed) const
115 return Hash<intptr_t>()(intptr_t(p), seed);
118 unsigned operator()(const void* const& p) const
120 return Hash<intptr_t>()(intptr_t(p));
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 } // End namespace Foam
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 // ************************************************************************* //