|
Boost Users : |
From: Boris Mansencal (boris.mansencal_at_[hidden])
Date: 2006-12-04 10:03:49
Peter Dimov wrote:
>Boris Mansencal wrote:
>
>
>>I would like to use TR1 unordered_map for a 2D point custom data type.
>>For this, I use hash_value from Boost. But I would like to give/pass a
>>context to this function : here, width & height of domain in which are
>>my 2D points.
>>Currently, I declare theses width and height static. My code (in my
>>cpp file) looks like :
>>
>>static int P_width;
>>static int P_height;
>>std::size_t hash_value(point const& p)
>>{
>> return ((size_t)p.x()<<1)*P_width + (size_t)(p.y()<<1);
>>}
>>
>>But this solution is not satisfactory as I can not have several
>>instances of my class including the unordered_map, i.e., several
>>domains of different width & height.
>>
>>Is there a straightforward solution that I have overlooked ?
>>
>>
>
>Is the context-free solution
>
>std::size_t hash_value(point const& p)
>{
> std::size_t seed( 0 );
>
> hash_combine( seed, p.x() );
> hash_combine( seed, p.y() );
>
> return seed;
>}
>
>not working for you?
>
>http://boost.org/doc/html/hash/combine.html
>
>
It is working... but my tests show better performances when I use my
hash function (using width & height) instead of this hash_combine solution.
Is there no solution to my question ?
(I am not a hash function specialist, so if you have a better hash
function, for 2D points in width*height domain, context free or not, I
would be happy to know...)
Boris.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net