[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hash resizing bug

From: Jim Meyering
Subject: Re: hash resizing bug
Date: Thu, 18 Jun 2009 16:40:03 +0200

Eric Blake wrote:
> I haven't pushed the second one to savannah yet; what do you think of it?
>  Sometimes it is desirable to hash distinct pointers, in which case
> allowing a NULL user function to request this seems to make sense.  My
> design choice was to provide trivial functions at initialization rather
> than penalize normal users by checking at every use of the callback
> whether the function was NULL.

Yes, I've often hashed pointer values.
However, note that the low bits of a pointer are often zero,
so that for small table sizes, this may be a very poor choice.

In applications that hash only malloc'd pointers I've used this:

hash_address (const void *addr, size_t table_size)
  size_t k = (size_t) addr;
  assert (k % 4 == 0);
  return (k / 4) % table_size;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]