1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-23 15:50:05 +02:00

Correct test of equality of hash maps

This commit is contained in:
Paul Licameli 2018-01-09 00:59:15 -05:00
parent bec6f237bc
commit 498747269c

View File

@ -306,19 +306,17 @@ void Tags::Clear()
namespace { namespace {
bool EqualMaps(const TagMap &map1, const TagMap &map2) bool EqualMaps(const TagMap &map1, const TagMap &map2)
{ {
for (auto it1 = map1.begin(), end1 = map1.end(), // Maps are unordered, hash maps; can't just iterate in tandem and
it2 = map2.begin(), end2 = map2.end(); // compare.
it1 != end1 || it2 != end2;) { auto copy(map1);
if (it1 == end1 || it2 == end2) for (const auto &pair : map2) {
auto iter = copy.find(pair.first);
if (iter == copy.end() || iter->second != pair.second)
return false; return false;
else if (it1->first != it2->first) copy.erase(iter);
return false;
else if (it1->second != it2->second)
return false;
else
++it1, ++it2;
} }
return true;
return copy.empty();
} }
} }