Closed
Bug 817769
Opened 13 years ago
Closed 13 years ago
Add priority queue utility class
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
FIXED
mozilla20
People
(Reporter: bhackett1024, Unassigned)
References
Details
Attachments
(1 file)
5.00 KB,
patch
|
luke
:
review+
|
Details | Diff | Splinter Review |
Bug 814966 needs an efficient priority queue implementation. Rather than do this as a one/off implementation it'd be nice to have a generic class. Heap based priority queues represent a binary tree with a fixed array of data, so a Vector can be used for backing storage and little new logic is required. (No uses of the class are included in this patch, but with an in progress one for bug 814966 this stuff does actually work).
Attachment #687909 -
Flags: review?(luke)
![]() |
||
Comment 1•13 years ago
|
||
Comment on attachment 687909 [details] [diff] [review]
patch
Review of attachment 687909 [details] [diff] [review]:
-----------------------------------------------------------------
Looks great!
I remembered after talking on IRC that js/src/ds/PriorityQueue.h might be a better initial place for this since ds/* headers aren't exported whereas, as the name implies, js/public/* headers are and PriorityQueue.h isn't needed outside js/src.
::: js/public/PriorityQueue.h
@@ +125,5 @@
> + continue;
> + }
> +
> + break;
> + }
Although this loop structure is symmetric with shiftDown, I think it would read a little nicer as:
while (n > 0) {
size_t parent = (n - 1) / 2;
if (P::priority(heap[parent]) >= P::priority(heap[n]))
break;
swap(n, parent);
n = parent;
}
Attachment #687909 -
Flags: review?(luke) → review+
Reporter | ||
Comment 2•13 years ago
|
||
Comment 3•13 years ago
|
||
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla20
You need to log in
before you can comment on or make changes to this bug.
Description
•