This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Enhance std::hash for pointers
- From: Christopher Jefferson <chris at bubblescope dot net>
- To: FranÃois Dumont <frs dot dumont at gmail dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 8 May 2015 23:10:52 +0100
- Subject: Re: Enhance std::hash for pointers
- Authentication-results: sourceware.org; auth=none
- References: <554A751E dot 9030009 at gmail dot com> <CAFiYyc2asQNBV2_1ezunOnVeVDpDzF5nBE4jyD+2t6PvsPJGYA at mail dot gmail dot com> <554D1A05 dot 9070601 at gmail dot com>
My concern with accepting this patch is that many of libstdc++'s hash
functions are awful from a mixing point of view -- you would get
exactly the same problem from users who have integers which are always
a multiple of a power of 2 (which is in practice not uncommon). This
would give exactly the same problem.
Rather than try to "fix" one hash function like this, we should just
accept our hash functions might have low quality lower order bits.
On 8 May 2015 at 21:18, FranÃois Dumont <frs.dumont@gmail.com> wrote:
> On 08/05/2015 10:02, Richard Biener wrote:
>>
>> On Wed, May 6, 2015 at 10:10 PM, FranÃois Dumont <frs.dumont@gmail.com>
>> wrote:
>>>
>>> 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 you use a real hashing function that's not true. That is, something
>> else than GCCs pointer_hash (void *p) { return (uintptr_t)p >>3; }.
>
>
> Sorry, I don't understand your remark. Do you mean that if someone is not
> using std::hash to hash its pointers he won't benefit from the enhancement ?
>
> It is a good point however to see that gcc is using something similar
> internally.
>
> FranÃois
>