1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Hash function class for primitives. All non-primitives used to hash
30 entries on hash tables likely need a specialized version of this class.
32 \*---------------------------------------------------------------------------*/
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 /*---------------------------------------------------------------------------*\
48 Class Hash Declaration
49 \*---------------------------------------------------------------------------*/
51 template<class PrimitiveType>
59 unsigned operator()(const PrimitiveType& p, unsigned seed) const
61 return Hasher(&p, sizeof(p), seed);
64 unsigned operator()(const PrimitiveType& p) const
66 return Hasher(&p, sizeof(p));
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 //- Hash specialization for hashing pointer addresses.
75 // Treat a pointer like a long.
76 // This should work for both 32-bit and 64-bit pointers.
85 unsigned operator()(const void* const& p, unsigned seed) const
87 return Hash<long>()(long(p), seed);
90 unsigned operator()(const void* const& p) const
92 return Hash<long>()(long(p));
98 //- Hash specialization for hashing labels
100 class Hash<Foam::label>
107 //- Incrementally hash a label.
108 // This will necessarily return a different value than the
109 // non-incremental version.
110 unsigned operator()(const label& p, unsigned seed) const
112 return Hasher(&p, sizeof(label), seed);
115 //- Return the unsigned representation of a label.
116 // This helps if people have relied on the hash value corresponding to
117 // the natural order.
118 unsigned operator()(const label& p) const
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 } // End namespace Foam
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 // ************************************************************************* //