Boost logo

Boost :

From: Daniel James (daniel_james_at_[hidden])
Date: 2006-03-20 15:37:15


Alexei Alexandrov wrote:
> Hi boosters,
>
> I believe this question should already have been raised but I can't find any info on this:
> Why boost::hash is not specialized for 64-bit types by default? Is there any reasonable reason for that?
>
> Thanks a lot for the answer and for Boost itself.

By 64-bit types I guess you mean 'long long'? Mainly because it wasn't
specified in Peter's original paper. But there is a problem with
implementing it. The integer hashes are defined as:

     std::size_t hash_value(val) { return val; }

This is fine for most types, but since long long typically has a much
larger range of values than std::size_t, it will work very badly for
long long.

The reasoning behind explicitly defining the function in the
specification it so that it should have predictable quality on different
platforms and should give equal hash values for equivalent values of
different types.

I think it's possible to change the definition to one that remains close
to the spirit of the original specification and works well for the
larger integer types. I'll be looking into doing this for Boost 1.35.

Daniel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk