Deutsch English Français Italiano |
<v2nkbq$1pt1p$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Richard Harnden <richard.nospam@gmail.invalid> Newsgroups: comp.lang.c Subject: Re: Good hash for pointers Date: Thu, 23 May 2024 15:37:44 +0100 Organization: A noiseless patient Spider Lines: 15 Message-ID: <v2nkbq$1pt1p$1@dont-email.me> References: <v2n88p$1nlcc$1@dont-email.me> Reply-To: richard.harnden@invalid.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 23 May 2024 16:37:47 +0200 (CEST) Injection-Info: dont-email.me; posting-host="78bf7c45fd6dacd6c6c79a162076f10f"; logging-data="1897529"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ofUhko4GeMcz6zy53J8iJq/8tWCe9mY0=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:m+y3V9ev+YVwlxUmeq82VFJq/nI= In-Reply-To: <v2n88p$1nlcc$1@dont-email.me> Content-Language: en-GB Bytes: 1490 On 23/05/2024 12:11, Malcolm McLean wrote: > > What is a good hash function for pointers to use in portable ANSI C? All your pointers from malloc are going to be unique. All of their low bits are going to be zero, because they need to align on some n-bit boundary. All of their high bit are going to be the same, because that's just how it works. So just take the middle: hash = ((intptr_t) ptr) >> 4 & 0xffff; Good enough?