Boost logo

Boost Users :

Subject: Re: [Boost-users] [unordered] Merging unordered maps
From: Daniel James (dnljms_at_[hidden])
Date: 2014-05-29 12:43:44


On 29 May 2014 17:24, Pete bartlett <pete_at_[hidden]> wrote:
> I have a performance hotspot when merging a few unordered_maps of the same type into a master unordered_map (also of the same type)
>
> Currently I am doing
>
> Foreach( auto const& submap ,submaps )
> Master.insert( submap.begin() , submap.end() );
>
> This seems to be somewhat wasteful because the insert is (I think) computing hashes that the submaps already "know".
>
> Can I improve on this
> - without changing Boost?

Not as far as I know.

> - without changing the boost interface, but changing the implementation (eg specialising the insert for certain iterator types)?

I don't think so. In your example the problem is that the iterator
only points to the nodes, which happen to contain the hash values, but
there's no way of telling if they were generated by the same hash
function.

> - some more intrusive change?

Maybe. Could write a function that inserts from another container,
rather than using iterators. It is now possible to tell if the same
hash function type was used, but it isn't possible to tell that
they're equal (eg. when using a randomized hash function, the hash
values might not be the same for two different instances). It might be
possible to create a type trait to detect if the hash function has an
equality operator - and assume they're not equal if it doesn't.

> If the second or third option, would the maintainer be willing to consider merging the change into Boost proper?

I would have to think about it.


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