Deutsch   English   Français   Italiano  
<v2qk3h$2e6vs$2@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Good hash for pointers
Date: Fri, 24 May 2024 10:51:45 -0700
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <v2qk3h$2e6vs$2@dont-email.me>
References: <v2n88p$1nlcc$1@dont-email.me> <86v834i1o9.fsf@linuxsc.com>
 <v2okbv$1vp4n$2@dont-email.me> <86r0dshysc.fsf@linuxsc.com>
 <v2omvt$2049k$1@dont-email.me> <86ed9shtsj.fsf@linuxsc.com>
 <v2ppac$29ca1$1@dont-email.me> <v2ps9g$29v2e$1@dont-email.me>
 <v2qjvm$2e6vs$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 24 May 2024 19:51:46 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a99698c67443521d1279cccaa6d71273";
	logging-data="2563068"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+m6Iawu12KAznpnUD3mKiiiQS8VNgzPmw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:EQOG+cyNsaKXWIySgFUm0kbFKf4=
Content-Language: en-US
In-Reply-To: <v2qjvm$2e6vs$1@dont-email.me>
Bytes: 2214

On 5/24/2024 10:49 AM, Chris M. Thomasson wrote:
> On 5/24/2024 4:05 AM, Malcolm McLean wrote:
> [...]
>> Then I can't be the first person to want to use a pointer as a key for 
>> hash table.
>>
>> And I don't want things to break if pointer representation changes.
> 
> Check this out, it relies on hashing pointers, the multex... ;^)
> 
> https://groups.google.com/g/comp.lang.c++/c/sV4WC_cBb9Q/m/SkSqpSxGCAAJ
> 
> It can be used for many different things...
> 
> 

The naive hash is:
______________________
// A table of locks
struct mutex_table
{
   std::vector<std::mutex> m_locks;

   mutex_table(std::size_t size) : m_locks(size) { assert(size > 0); }

   // totally contrived simple hash...
   std::size_t hash(void const* ptr)
   {
     std::uintptr_t ptr_uint = (std::uintptr_t)ptr;
     return (std::size_t)(((ptr_uint << 9) * 103) % m_locks.size());
   }
};
______________________

;^)