yangxu998 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

MinMaxPriorityQueue: Sorted order iteration without removing elements #554

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The current iterator() returns an Iterator with unpredictable iteration order. 
It seems natural that such a data structure could provide an ordered iterator 
method, perhaps in addition to the one provided.

Original issue reported on code.google.com by hein.mel...@gmail.com on 19 Feb 2011 at 4:59

GoogleCodeExporter commented 9 years ago
That would be bad. To implement this, you have to destroy the queue. But since 
iterators are not supposed to be destructive, you'd need to create internally a 
copy and destroy /that/ instead. If you were willing to do that, copying and 
polling one by one would be just as good, so the net effect would be that you 
simply lose an efficient way to access all elements of the queue.

Compare with java.util.PriorityQueue.

Original comment by jim.andreou on 19 Feb 2011 at 6:04

GoogleCodeExporter commented 9 years ago
I was sort of expecting this, but was hoping that it would be possible to do 
some internal tricks in the datastructure to not screw up the queue, e.g. by 
simulating removal with separate index pointers. But I haven't studied the code 
sufficiently to understand if that would be possible.

Original comment by hein.mel...@gmail.com on 19 Feb 2011 at 8:35

GoogleCodeExporter commented 9 years ago
For what you want, use a SortedSet.

Original comment by kevin...@gmail.com on 19 Feb 2011 at 11:48

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09