diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H index 413dda4aa4..57cf7af96d 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H @@ -52,7 +52,7 @@ Typedef Foam::wordHashSet Description - A HashSet with (the default) word keys. + A HashSet with word keys and string hasher. Typedef Foam::labelHashSet @@ -75,12 +75,22 @@ namespace Foam // Forward Declarations template class MinMax; +template class HashSet; + +// Common hash-set types + +//- A HashSet of words, uses string hasher. +typedef HashSet> wordHashSet; + +//- A HashSet of labels, uses label hasher. +typedef HashSet> labelHashSet; + /*---------------------------------------------------------------------------*\ Class HashSet Declaration \*---------------------------------------------------------------------------*/ -template> +template> class HashSet : public HashTable @@ -401,14 +411,7 @@ public: }; -// Typedefs - -//- A HashSet with word keys. -typedef HashSet wordHashSet; - -//- A HashSet with label keys and label hasher. -typedef HashSet> labelHashSet; - +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Global Functions diff --git a/src/OpenFOAM/containers/HashTables/HashTableFwd.H b/src/OpenFOAM/containers/HashTables/HashTableFwd.H index 786bd653b9..dbf9ed7dfd 100644 --- a/src/OpenFOAM/containers/HashTables/HashTableFwd.H +++ b/src/OpenFOAM/containers/HashTables/HashTableFwd.H @@ -39,9 +39,10 @@ Description namespace Foam { +template class HashSet; + template class HashTable; template class HashPtrTable; -template class HashSet; template class Map; template class PtrMap; diff --git a/src/OpenFOAM/expressions/exprString/exprString.H b/src/OpenFOAM/expressions/exprString/exprString.H index a7aa13f577..9a670930f2 100644 --- a/src/OpenFOAM/expressions/exprString/exprString.H +++ b/src/OpenFOAM/expressions/exprString/exprString.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Original code Copyright (C) 2012-2018 Bernhard Gschaider - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2012-2018 Bernhard Gschaider + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,7 +65,7 @@ public: // Constructors - //- Construct null + //- Default construct exprString() = default; //- Copy construct @@ -189,6 +189,16 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace expressions + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Hashing for exprString is the same as string +template<> struct Hash : string::hasher {}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/hashes/Hash/Hash.H b/src/OpenFOAM/primitives/hashes/Hash/Hash.H index 5329080bf0..ec78dc1b57 100644 --- a/src/OpenFOAM/primitives/hashes/Hash/Hash.H +++ b/src/OpenFOAM/primitives/hashes/Hash/Hash.H @@ -30,12 +30,9 @@ Class Description Hash function class. The default definition is for primitives. - Non-primitives used to hash entries on hash tables will likely need + Non-primitives used to hash entries on hash tables will need a specialized version. -Note - The second template parameter (bool) is used for SFINAE overloading, - \*---------------------------------------------------------------------------*/ #ifndef Hash_H @@ -43,8 +40,6 @@ Note #include "Hasher.H" #include -#include -#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -55,7 +50,7 @@ namespace Foam Class Hash Declaration \*---------------------------------------------------------------------------*/ -template +template struct Hash { unsigned operator()(const T& obj, unsigned seed=0) const @@ -67,35 +62,7 @@ struct Hash // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Specialization for trivial (integer) types - -#undef FOAM_INTHASHER -#define FOAM_INTHASHER(IntType) \ - /*! \brief Hashing specialization for IntType */ \ - /*! Unseeded (single value) uses natural order, otherwise incremental */ \ - template<> struct Hash \ - { \ - unsigned operator()(const IntType val) const \ - { \ - return static_cast(val); \ - } \ - unsigned operator()(const IntType val, unsigned seed) const \ - { \ - return Foam::Hasher(&val, sizeof(IntType), seed); \ - } \ - } - -FOAM_INTHASHER(bool); -FOAM_INTHASHER(char); -FOAM_INTHASHER(int32_t); -FOAM_INTHASHER(int64_t); -FOAM_INTHASHER(uint32_t); - -#undef FOAM_INTHASHER - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -//- Hashing specialization for nullptr. Always 0 +//- Hashing of nullptr, always 0 template<> struct Hash { @@ -105,7 +72,7 @@ struct Hash } }; -//- Hashing specialization for pointers, interpret pointer as a integer type +//- Hashing of pointers, treat as unsigned integer template<> struct Hash { @@ -119,20 +86,32 @@ struct Hash // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -//- Hashing partial specialization for derived string types -template -struct Hash -< - StringType, - typename std::enable_if - ::value, bool>::type -> -{ - unsigned operator()(const std::string& str, unsigned seed=0) const - { - return Foam::Hasher(str.data(), str.length(), seed); +// Specialization for common integral types + +#undef FOAM_HASH_SPECIALIZATION +#define FOAM_HASH_SPECIALIZATION(Type) \ + \ + /*! \brief Hashing of integral type: Type */ \ + /*! Unseeded (single value) uses natural order, otherwise incremental */ \ + template<> \ + struct Hash \ + { \ + unsigned operator()(const Type val) const \ + { \ + return static_cast(val); \ + } \ + unsigned operator()(const Type val, unsigned seed) const \ + { \ + return Foam::Hasher(&val, sizeof(Type), seed); \ + } \ } -}; + +FOAM_HASH_SPECIALIZATION(bool); +FOAM_HASH_SPECIALIZATION(char); +FOAM_HASH_SPECIALIZATION(int32_t); +FOAM_HASH_SPECIALIZATION(int64_t); +FOAM_HASH_SPECIALIZATION(uint32_t); +#undef FOAM_HASH_SPECIALIZATION // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index cc1cd4cacf..41ef3f9c03 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -58,10 +58,15 @@ namespace Foam // Forward Declarations class fileName; class token; + template class List; template class UList; typedef List wordList; +//- Hashing for fileName +template<> struct Hash : string::hasher {}; + + /*---------------------------------------------------------------------------*\ Class fileName Declaration \*---------------------------------------------------------------------------*/ diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.H b/src/OpenFOAM/primitives/strings/keyType/keyType.H index 7ed8fe64b6..bcba95958d 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyType.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyType.H @@ -58,6 +58,10 @@ class token; Istream& operator>>(Istream& is, keyType& val); Ostream& operator<<(Ostream& os, const keyType& val); +//- Hashing for keyType +template<> struct Hash : string::hasher {}; + + /*---------------------------------------------------------------------------*\ Class keyType Declaration \*---------------------------------------------------------------------------*/ @@ -237,6 +241,8 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // IOstream Operators //- Read operator diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index 52794f905c..d5646b4b62 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -62,11 +62,14 @@ namespace Foam { // Forward Declarations +class string; class word; class wordRe; class Istream; class Ostream; +template struct Hash; + /*---------------------------------------------------------------------------*\ Class string Declaration \*---------------------------------------------------------------------------*/ @@ -150,7 +153,8 @@ public: } }; - //- Hashing functor for string and derived string classes + //- Deprecated hashing functor - use hasher + // \deprecated(2021-04) - use hasher struct hash : string::hasher {}; @@ -333,6 +337,17 @@ public: }; +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +//- Hashing for Foam::string +template<> struct Hash : string::hasher {}; + +//- Hashing for std:::string +template<> struct Hash : string::hasher {}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // IOstream Operators //- Read operator diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H index 19d9c2a874..0332781130 100644 --- a/src/OpenFOAM/primitives/strings/word/word.H +++ b/src/OpenFOAM/primitives/strings/word/word.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,6 +55,10 @@ class word; Istream& operator>>(Istream& is, word& val); Ostream& operator<<(Ostream& os, const word& val); +//- Hashing for word +template<> struct Hash : string::hasher {}; + + /*---------------------------------------------------------------------------*\ Class word Declaration \*---------------------------------------------------------------------------*/ @@ -204,6 +208,8 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // IOstream Operators //- Read operator diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H index c1467d8d42..b5b0536e34 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H @@ -70,6 +70,10 @@ class wordRe; Istream& operator>>(Istream& is, wordRe& val); Ostream& operator<<(Ostream& os, const wordRe& val); +//- Hashing for wordRe +template<> struct Hash : string::hasher {}; + + /*---------------------------------------------------------------------------*\ Class wordRe Declaration \*---------------------------------------------------------------------------*/ @@ -249,6 +253,8 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // IOstream Operators //- Read operator diff --git a/src/fileFormats/ensight/name/ensightFileName.H b/src/fileFormats/ensight/name/ensightFileName.H index caa47c7ef8..0e15cb1919 100644 --- a/src/fileFormats/ensight/name/ensightFileName.H +++ b/src/fileFormats/ensight/name/ensightFileName.H @@ -106,6 +106,15 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace ensight + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Hashing for FileName is the same as string +template<> struct Hash : string::hasher {}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/fileFormats/ensight/name/ensightVarName.H b/src/fileFormats/ensight/name/ensightVarName.H index 4f6c01f3ec..dab88dd446 100644 --- a/src/fileFormats/ensight/name/ensightVarName.H +++ b/src/fileFormats/ensight/name/ensightVarName.H @@ -104,6 +104,16 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace ensight + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Hashing for VarName is the same as string +template<> struct Hash : string::hasher {}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //