Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-03-20 16:36:09


Daniel James wrote:

> 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.

For larger integer types, we probably need something along the lines of

std::size_t hash_value( val )
{
    size_t r = val;

    while( val >>= size_t_bits )
    {
        hash_combine( r, (size_t)val );
    }

    return r;
}

It has the property of preserving the hash_value of all _values_ that can
fit into a size_t, even though the underlying type is capable of holding
bigger integers.


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