December 27, 20178 yr 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, 20178 yr by Qubit
December 27, 20178 yr Delete entries that have changed and re enter them in the priority queue for it to remain ordered.
December 27, 20178 yr Author 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
December 27, 20178 yr 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
Create an account or sign in to comment