From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55054 invoked by alias); 8 May 2015 08:02:17 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 55025 invoked by uid 89); 8 May 2015 08:02:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-ob0-f178.google.com Received: from mail-ob0-f178.google.com (HELO mail-ob0-f178.google.com) (209.85.214.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 08 May 2015 08:02:15 +0000 Received: by obcus9 with SMTP id us9so20462534obc.2; Fri, 08 May 2015 01:02:13 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.182.158.166 with SMTP id wv6mr2132378obb.52.1431072133483; Fri, 08 May 2015 01:02:13 -0700 (PDT) Received: by 10.76.115.167 with HTTP; Fri, 8 May 2015 01:02:13 -0700 (PDT) In-Reply-To: <554A751E.9030009@gmail.com> References: <554A751E.9030009@gmail.com> Date: Fri, 08 May 2015 08:02:00 -0000 Message-ID: Subject: Re: Enhance std::hash for pointers From: Richard Biener To: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= Cc: "libstdc++@gcc.gnu.org" , gcc-patches Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg00624.txt.bz2 On Wed, May 6, 2015 at 10:10 PM, Fran=C3=A7ois Dumont wrote: > Hi > > Following Marc Glisse comment #4 > on:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D65641 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 ne= eds > 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 b= ut 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; }. Richard. > if anyone has a good method to prove it I can try to implement it. The te= st > I have added in quality.cc is very basic and just reflect enhancement > following Marc's comment. > > 2015-05-05 Fran=C3=A7ois Dumont > > * include/bits/functional_hash.h > (std::__detail::_Lowest_power_of_two): New. > (std::hash<_Tp*>::operator()): Use latter. > * testsuite/20_util/hash/quality.cc (pointer_quality_test): New. > > Tested under Linux x86_64. > > Fran=C3=A7ois >