Finding top elements of a map using Heap

I have a unordered_hashmap that maps a string (say personName or SSN) to a struct Attributes that has many attributes of that person including annualIncome. There are many such hash maps corresponding to different organizations such as mapOrganizationA, mapOrganizationB etc. I need to find the people (with attributes) with the top-k annual incomes. I was thinking of using a min-heap with k-nodes (with the minimum salary as root), so that I can scan the maps one by one, of the current element has income more than the root of the min-heap, the root can be updated. Is this the right approach to get top-k from different maps? Is there a min-heap datastucture in STL I can make use of.


You can use make_heap, push_heap, pop_heap, sort_heap, is_heap to treat any non-associative container (or sequence, really) as a heap.

That would not fit you map nicely, but I assume nothing would prevent you from storing the values (or pointers/references to those) inside, say, a list for this purpose?

Also, perhaps look at Boost.MultiIndex which is a library precisely focused on providing multiple (efficient!) indexes on the same data

Need Your Help

'mvn release:perform' takes too long when deploying to Archiva

maven-release-plugin archiva

'mvn release:perform' takes too long to deploy artifacts to Archiva. The logs shows that the 'release:perform' do its job quickly (test, package, source, javadoc...) but it takes too match time to MVC exception not being caught in try catch block validation model

Could anyone tell me why a problem in the noun model would not be caught by this try catch?