File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -322,6 +322,27 @@ class HashMap {
322322 return hash_map_clone;
323323 }
324324
325+ bool operator ==(HashMap const & other) const
326+ {
327+ if (size () != other.size ())
328+ return false ;
329+ if (is_empty ())
330+ return true ;
331+ for (auto const & [key, value] : *this ) {
332+ auto it = other.find (key);
333+ if (it == other.end ())
334+ return false ;
335+ if (!ValueTraits::equals (value, it->value ))
336+ return false ;
337+ }
338+ return true ;
339+ }
340+
341+ bool operator !=(HashMap const & other) const
342+ {
343+ return !(*this == other);
344+ }
345+
325346private:
326347 HashTableType m_table;
327348};
Original file line number Diff line number Diff line change @@ -353,3 +353,18 @@ TEST_CASE(update)
353353 second.update (first);
354354 EXPECT_EQ (4u , second.size ());
355355}
356+
357+ TEST_CASE (compare)
358+ {
359+ HashMap<int , int > first;
360+ HashMap<int , int > second;
361+
362+ EXPECT_EQ (first, second);
363+
364+ first.set (1 , 10 );
365+ second.set (1 , 10 );
366+ EXPECT_EQ (first, second);
367+
368+ first.set (2 , 20 );
369+ EXPECT_NE (second, first);
370+ }
You can’t perform that action at this time.
0 commit comments