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:

size_t
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