Boost logo

Boost :

Subject: Re: [boost] [gil] Pixel Hasher
From: Harg Tholan (hargtholan_at_[hidden])
Date: 2013-03-26 10:25:09


Ok, I guess you solution is better for it uses "static_for_each" which
would turn into statically generated code.
But we may skip pushing stuff into a vector by doing

std::size_t hash = 0;
static_for_each( p, [&] ( const channel_t& c )
        {
           boost::hash_combine(hash, c);
        });

return hash;

Do we agree with this?
Regards.

2013/3/26 Christian Henning <chhenning_at_[hidden]>

> On Tue, Mar 26, 2013 at 9:51 AM, Harg Tholan <hargtholan_at_[hidden]> wrote:
> > Do you mean that unordered_map can automatically instantiate a hashing
> > function for any type of pixel? I have tried this:
>
> Ok, I see I was wrong. I simple solution is provided here:
>
>
> http://stackoverflow.com/questions/10405030/c-unordered-map-fail-when-used-with-a-vector-as-key
>
> Taking that you can create the following:
>
> template< typename Pixel >
> struct pixel_hasher
> {
> std::size_t operator()( const Pixel& p ) const
> {
> typedef channel_type<Pixel>::type channel_t;
>
> vector<channel_t> v;
> static_for_each( p, [&] ( const channel_t& c )
> {
> v.push_back( c );
> });
>
> return boost::hash_range( v.begin(), v.end() );
> }
> };
>
>
> typedef rgb8_pixel_t pixel_t;
> pixel_t p( 1,2,3);
> unordered_map< pixel_t, int, pixel_hasher< pixel_t > > n;
> n[p] = 99;
>
> Hope this helps.
>
> Christian
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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