Merge pull request #1469 from atgeirr/fix-fmap-comparison

Fix operator==() of UDQFunctionTable.
This commit is contained in:
Joakim Hove 2020-02-14 09:06:39 +01:00 committed by GitHub
commit ecd8d98aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <map>
#include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQFunctionTable.hpp>
@ -132,9 +133,19 @@ bool UDQFunctionTable::operator==(const UDQFunctionTable& data) const {
if (this->functionMap().size() != data.functionMap().size()) if (this->functionMap().size() != data.functionMap().size())
return false; return false;
auto tIt = this->functionMap().begin(); // Simply using the operator== method of std::unordered_map would
auto dIt = data.functionMap().begin(); // compare the pointers contained and not the objects pointed to.
for (; tIt != this->functionMap().end(); ++tIt, ++dIt) { // We therefore must iterate manually through the container. The
// order of the map elements does not matter, and is
// indeterminate. Sorting must be done before comparision so that
// we compare elements with the same key to each other.
using SortedMap = std::map<std::string, std::shared_ptr<UDQFunction>>;
SortedMap sorted_fmap(this->functionMap().begin(), this->functionMap().end());
SortedMap data_sorted_fmap(data.functionMap().begin(), data.functionMap().end());
auto tIt = sorted_fmap.begin();
auto dIt = data_sorted_fmap.begin();
for (; tIt != sorted_fmap.end(); ++tIt, ++dIt) {
if (tIt->first != dIt->first) if (tIt->first != dIt->first)
return false; return false;