The operator== of hashtable.h (also used in ext/hash_map.h) is broken. Even if the two hash tables being compared have the same key/value pairs, if the number of *buckets* is different, the == operator returns false. Looking at the code for the ==operator (line 698 of hashtable.h in the trunk of SVN), it returns false unless the number of buckets is the same (not the number of actual items in the hash table).
I'm not sure of the specification of == operators in the STL, but it seems that have the number of buckets be part of the == operator is very strange behavior. So, either this is a strangely-specific operation or the implementation of operator== of hashtable isn't correct. From looking at some other on-line documentation, it seems that this is indeed a bug. For example, from http://msdn2.microsoft.com/en-us/library/w2w623zh(VS.80).aspx: "The comparison between hash_map objects is based on a pairwise comparison of their elements. Two hash_maps are equal if they have the same number of elements and their respective elements have the same values. Otherwise, they are unequal." The code below illustrates the problem: hash_map<int, int> map1(100); hash_map<int, int> map2(1000); map1[10] = 10; map2[10] = 10; cout << (map1 == map2) << endl; The above code will print "0" instead of the expected "1". I verified this on g++ 4.1, but by looking at the latest code in SVN, the problem clearly hasn't been fixed. The code seems to rely on the number of buckets being the same to enable a parallel walk of the buckets of both hash tables. This comparison operation needs to be re-written to handle the case in which the number of buckets differs. Please feel free to contact me if you have any questions. -- Summary: The == operator of hashtable.h and hash_map.h is broken Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: milom at cis dot upenn dot edu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32910