COMP: use intptr_t instead of long for hashing pointers

This commit is contained in:
Mark Olesen
2019-03-15 10:03:12 +01:00
parent db1b1e8ad4
commit 62fa24080f

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010, 2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2010, 2018-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2012 OpenFOAM Foundation | Copyright (C) 2011-2012 OpenFOAM Foundation
@ -51,10 +51,10 @@ namespace Foam
Class Hash Declaration Class Hash Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class PrimitiveType> template<class T>
struct Hash struct Hash
{ {
inline unsigned operator()(const PrimitiveType& obj, unsigned seed=0) const inline unsigned operator()(const T& obj, unsigned seed=0) const
{ {
return Hasher(&obj, sizeof(obj), seed); return Hasher(&obj, sizeof(obj), seed);
} }
@ -140,19 +140,18 @@ struct Hash<Foam::keyType>
}; };
//- Hash specialization for pointers. //- Hash specialization for pointers, interpret pointer as a integer type.
// Interpret pointer as a long (works for 32-bit and 64-bit pointers).
template<> template<>
struct Hash<void*> struct Hash<void*>
{ {
inline unsigned operator()(const void* const& obj, unsigned seed) const inline unsigned operator()(const void* const& obj, unsigned seed) const
{ {
return Hash<long>()(long(obj), seed); return Hash<intptr_t>()(intptr_t(obj), seed);
} }
inline unsigned operator()(const void* const& obj) const inline unsigned operator()(const void* const& obj) const
{ {
return Hash<long>()(long(obj)); return Hash<intptr_t>()(intptr_t(obj));
} }
}; };