Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2024-12-08 20:45:51


On 12/8/24 21:31, Peter Dimov via Boost wrote:
>> 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.

This would be incompatible with algorithms that don't support multiple
calls to finalize().


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