[Click] HashMap consolidation

Eddie Kohler kohler at icir.org
Thu Oct 9 22:41:06 EDT 2003


Hi all,

We have had two hash table templates (HashMap and BigHashMap) for over
three years. This is pretty annoying and there was no guidance about which
was appropriate when (except that only BigHashMap supported remove(), while
only HashMap supported operator=).

I just did some speed tests and, on a set of String lookups (which you can
see in elements/test/bhmtest.cc; a combination of lookups and failing
lookups), BigHashMap outperformed HashMap by about 15-25%.

Therefore, I have removed HashMap from the repository, and renamed
BigHashMap to HashMap. (And gave BHM an operator=.)

This may cause gotchas with iterators. Formerly, you could say

   ... const HashMap<K, V> &map ...
   for (HashMap<K, V>::iterator i = map.begin(); i; i++)
     ...

That will now fail to compile, because "begin()" returns an object of type
"const_iterator" when called on a const HashMap. Use this code instead:

   ... const HashMap<K, V> &map ...
   for (HashMap<K, V>::const_iterator i = map.begin(); i; i++)
     ...

The STL does this too. (Also note that you can change the value() of an
"iterator", but not that of a "const_iterator".)

Please let the list know if there are problems.

Eddie


More information about the click mailing list