hashtable::erase and ::count enhancements

François Dumont frs.dumont@gmail.com
Thu Oct 6 21:02:00 GMT 2011


Hi

     When working on hashtable code I found 2 small optimizations for 
current hashtable implementation. In count method we know that all 
equivalent elements are next to each others in the bucket so I split the 
loop to stop counting once we found a not matching element in the second 
loop. In erase, I did some refactoring and I avoid to call _M_compare 
twice on the first matching node. I hope the unusual in libstdc++ 
do/while is not a problem.

2011-10-06  François Dumont <fdumont@gcc.gnu.org>

         * include/bits/hashtable.h (_Hashtable<>::erase(const key_type&)):
         Simplify implementation and avoid redundant comparison check on 
first
         matching element.
         * include/bits/hashtable.h (_Hashtable<>::count(const key_type&)):
         Once found a matching element, stop counting as soon as found a not
         matching one.

Tested on Linux x86_64.

Ok to commit ?

     I also find the _Hash_code_base::_M_compare counter intuitive as 
usually compare methods are returning false when the compared elements 
are equivalent and true otherwise which is exactly the opposite of this 
_M_compare method. Do you mind if I rename it _M_equal ? I will submit a 
patch for that if you don't.

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable.patch
Type: text/x-patch
Size: 2618 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20111006/0965ca0b/attachment.bin>


More information about the Libstdc++ mailing list