@@ -66,18 +66,18 @@ Strategies
6666==========
6767
6868We can implement this with a regular` Array ` . We'll keep it sorted inversely,
69- so` queue.dequeue() ` maps to` array.pop() ` .
69+ so` queue.dequeue() ` maps to` array.pop() ` . Each` queue() ` is a` splice() ` ,
70+ which rewrites the entire array. This is fast for tiny queues.
7071
71- But with an` Array ` , we'll need to` splice() ` , which can affect every single
72- element in the array. An alternative is to create a
73- [ Binary Heap] ( http://en.wikipedia.org/wiki/Binary_heap ) , which writes far
74- fewer array elements when queueing (though each element is written more slowly).
72+ An alternative is a[ Binary Heap] ( http://en.wikipedia.org/wiki/Binary_heap ) : it
73+ modifies just a few array elements when queueing (though each modification has
74+ a cost).
7575
7676Finally, we can use a[ B-Heap] ( http://en.wikipedia.org/wiki/B-heap ) . It's like a
77- binary heap, exceptit orders elements such that during a single operation,
78- writes occur closer to each other in memory. Unfortunately, it's slower to
79- calculate where in memory each write should occur (it costs a function call
80- instead of a bit-shift). So while it's fast in theory, it'sslower in practice.
77+ binary heap, exceptits modifications often occur close together in memory.
78+ Unfortunately, calculating _ where _ in memory the modifications should occur is
79+ slower. (It costs a function call instead of a bit-shift.) So while B-heap is
80+ fast in theory, it'sslow in practice.
8181
8282Create the queues like this:
8383
@@ -97,10 +97,11 @@ You'll see running times like this:
9797| Dequeue| O(1) (fast)| O(lg n)| O(lg n)|
9898
9999According to[ JsPerf] ( http://jsperf.com/js-priority-queue-queue-dequeue ) , the
100- fastest strategy for most cases is` BinaryHeapStrategy ` . Only use` ArrayStrategy `
101- only if you're queuing items in a very particular order. Don't use
102- ` BHeapStrategy ` , except as a lesson in how sometimes miracles in one
103- programming language aren't great in other languages.
100+ fastest strategy for most cases is` BinaryHeapStrategy ` . Use` ArrayStrategy `
101+ in edge cases, after performance-testing your specific data. Don't use
102+ ` BHeapStrategy ` : it's a lesson that a miracle in C can flop in JavaScript.
103+
104+ The default strategy is` BinaryHeapStrategy ` .
104105
105106Contributing
106107============