Qubit Posted December 27, 2017 Share Posted December 27, 2017 (edited) So I have a problem where I have a set of objects with two fields. I need to be able to get the min object of the set at a fast time (using a custom comparator). The problem is, when I get the min object set, it changes the fields of some objects in my original set. Thus, the ordering of the set needs to be changed when I am done with the min object. To me it seems obvious to use a priority queue with a custom comparator, the problem is, the Priority Queue in Java doesn't have a change or decrease key operation. I have tried looking for other implementations online for a priority queue that uses a comparator with the decrease key operation but I cannot find one. Any help would be greatly appreciated at to how to approach this problem? Edited December 27, 2017 by Qubit Quote Link to comment Share on other sites More sharing options...
dreameo Posted December 27, 2017 Share Posted December 27, 2017 Delete entries that have changed and re enter them in the priority queue for it to remain ordered. Quote Link to comment Share on other sites More sharing options...
Qubit Posted December 27, 2017 Author Share Posted December 27, 2017 5 minutes ago, dreameo said: Delete entries that have changed and re enter them in the priority queue for it to remain ordered. Problem is, the remove function in a PQ is linear and every time a min get removed, multiple objects get updated in the PQ. Thus many iterations of the whole PQ is needed Quote Link to comment Share on other sites More sharing options...
Septron Posted December 27, 2017 Share Posted December 27, 2017 Hmm, not sure I understand the situation completely but this is how I'd do what I think it is you're trying to do. https://gist.github.com/anonymous/920432652d87d5502a3cabfbdccd65bd 1 Quote Link to comment Share on other sites More sharing options...