1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. 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 \*---------------------------------------------------------------------------*/
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 /*---------------------------------------------------------------------------*\
47 Class Hash Declaration
48 \*---------------------------------------------------------------------------*/
50 template<class PrimitiveType>
58 unsigned operator()(const PrimitiveType& p, unsigned seed) const
60 return Hasher(&p, sizeof(p), seed);
63 unsigned operator()(const PrimitiveType& p) const
65 return Hasher(&p, sizeof(p));
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 //- Hash specialization for hashing pointer addresses.
74 // Treat a pointer like a long.
75 // This should work for both 32-bit and 64-bit pointers.
84 unsigned operator()(const void* const& p, unsigned seed) const
86 return Hash<long>()(long(p), seed);
89 unsigned operator()(const void* const& p) const
91 return Hash<long>()(long(p));
97 //- Hash specialization for hashing labels
99 class Hash<Foam::label>
106 //- Incrementally hash a label.
107 // This will necessarily return a different value than the
108 // non-incremental version.
109 unsigned operator()(const label p, unsigned seed) const
111 return Hasher(&p, sizeof(label), seed);
114 //- Return the unsigned representation of a label.
115 // This helps if people have relied on the hash value corresponding to
116 // the natural order.
117 unsigned operator()(const label p) const
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 } // End namespace Foam
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 // ************************************************************************* //