I am trying to implement Dijkstra's shortest path algorithm using C++ and STL. Since STL's priority queues do not support a decrease-key operation, I decided to use regular ordered sets. My algorithm is almost identical to this one.
However, I have some concerns. Namely, the ordering of the edges in the set will depend both upon the vertex number of the destination and the weight (as the regular relational operators of std::pair
will be used). I do believe that it should only depend on the weight. If I were to declare the set by using a custom comparator which would compare only the weights, how would I make std::set::erase
work, as it is needed to erase the edges between the same vertices but with greater weight?
Are there any other flaws that you guys can think of? Or do you perhaps have some better ideas than using std::set
?
Have a great Sunday, everyone.