Search code examples
c++stlheappriority-queue

How can I configure std::priority_queue to ignore duplicates?


How can I configure std::priority_queue to ignore duplicates?

When I add a key that is already contained then this new one should be ignored. (In my case, the priority for the old and the new one will always be exactly the same.)

Complexity-wise it should not make a difference: It will try to insert at the appropriate location, find the existing one there and do nothing. The question is just if std::priority_queue is configurable in that way.


Solution

  • You can implement a priority_queue out of an STL set.

    Implementing a priority queue that can be iterated over in C++