Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2024-12-08 18:31:45


> So, for example, if you have a 32 bit hash function and you need 64 bits, this
> is how you would do it, ordered from best to worst:
>
> // as good as possible
> uint64_t f1( Hash& hash )
> {
> uint32_t r1 = hash.result();
> uint32_t r2 = hash.result();
> return (uint64_t(r1) << 32) | r2;
> }
>
> // not that bad, but worse than the above
> uint64_t f2( Hash& hash )
> {
> return get_integral_result<uint64_t>( hash.result() );
> }

All that leads me to the thought that I've got get_integral_result wrong;
it should take the hash algorithm directly, not its result, and should
invoke result() as many times as needed to obtain the necessary
number of bits.

// best
uint64_t f0( Hash& hash )
{
    return get_integral_result<uint64_t>( hash );
}


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