Optimizing priority queue streaming algorithm in C++
You could create a

struct Element {
   int value;
   std::string id;
};


and store that in the priority queue. Then you don't need the map. Your compare function would of course only look at the value component:

struct compare {
   bool operator()(const Element&amp; l, const Element&amp; r) {
       return l.value &gt; r.value;
   }
};


Note that it is possible to use a naked function as comparator, it doesn't need to be a functor:

bool compare(const Element&amp; l, const Element&amp; r) {
   return l.value &gt; r.value;
}

std::priority_queue&lt;Element, std::vector&lt;Element&gt;, decltype(compare)&gt; heap(compare);