|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-13 10:50:56
Dave Harris wrote:
> In-Reply-To: <007e01c52597$b62c1980$6601a8c0_at_pdimov>
> pdimov_at_[hidden] (Peter Dimov) wrote (abridged):
>> pair<int, int>, int[2], struct { int a; int b; } are different
>> representations of the same thing; it is not strictly necessary for
>> them to use the same algorithm, but it's desirable and will
>> eliminate a source of confusion and mistakes.
>
> Really? What kind of mistakes?
>
> In my experience, if you want two different things to hash the same,
> you need to write their hash functions with that in mind. It is a special
> case which justifies not using the default hash function.
Maybe, but this is not an argument for making the hash values different.
>> size_t hash_range( size_t seed, It first, It last );
>
> I am also tempted by:
>
> size_t hash_range( It first, It last, size_t seed=0 );
>
> perhaps replacing the 0 with some other default value. So people can
> ignore it if they don't need it.
>
> But doesn't this mean that hash_value( pair<int,int> ) also needs a
> seed argument, if you want it to match hash_range( int[2] ) ?
No. The seed version of hash_range is used when you want to compute the hash
function of a sequence, but you don't have access to the whole sequence at
once. It's goal is not to provide a way to change the initial seed, but to
make it possible to continue from an intermediate seed.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk