diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index 298a0af95c..97cb2b321b 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -485,6 +485,43 @@ void HashTable::operator=(const HashTable& ht) } +template +bool HashTable::operator==(const HashTable& ht) + const +{ + // Are all my elements in ht? + for (const_iterator iter = begin(); iter != end(); ++iter) + { + const_iterator fnd = ht.find(iter.key()); + + if (fnd == ht.end() || (fnd() != iter())) + { + return false; + } + } + + // Are all ht elements in me? + for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter) + { + const_iterator fnd = find(iter.key()); + + if (fnd == end() || (fnd() != iter())) + { + return false; + } + } + return true; +} + + +template +bool HashTable::operator!=(const HashTable& ht) + const +{ + return !(operator==(ht)); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 02609be7fa..2f3913d2e2 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -223,6 +223,15 @@ public: //- Assignment void operator=(const HashTable&); + //- Equality. Two hashtables are equal if all contents of first are + // also in second and vice versa. So does not depend on table size or + // order! + bool operator==(const HashTable&) const; + + //- The opposite of the equality operation. Takes linear time. + bool operator!=(const HashTable&) const; + + // STL type definitions