Enhance std::hash for pointers

François Dumont frs.dumont@gmail.com
Wed May 6 20:10:00 GMT 2015


Hi

     Following Marc Glisse comment #4 
on:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65641 I would like to 
propose this enhancement to the hash functor for pointers. It simply 
gets rid of the irrelevant bits on pointers hash code based on memory 
alignment of the pointed type. The only drawback I can think of is that 
the type needs to be complete at std::hash instantiation time but is it 
really an issue ?

     IMO it is quite obvious that the resulting hash code will be better 
but if anyone has a good method to prove it I can try to implement it. 
The test I have added in quality.cc is very basic and just reflect 
enhancement following Marc's comment.

2015-05-05  François Dumont <fdumont@gcc.gnu.org>

     * include/bits/functional_hash.h
     (std::__detail::_Lowest_power_of_two<size_t>): New.
     (std::hash<_Tp*>::operator()): Use latter.
     * testsuite/20_util/hash/quality.cc (pointer_quality_test): New.

Tested under Linux x86_64.

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pointer_hash.patch
Type: text/x-patch
Size: 1782 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20150506/1ca054e8/attachment.bin>


More information about the Libstdc++ mailing list