Closed ezimuel closed 9 years ago
Does this have the same functionality as Zend\Stdlib\PriorityQueue
?
@akrabat Yes; they both follow the same signature as SplPriorityQueue, and FastPriorityQueue acts like PriorityQueue in that it has predictable ordering of items with the same priority, and iteration does not remove items.
Why not replace PriorityQueue
with this one?
PriorityQueue
implements IteratorAggregate
vs Iterator
, which means there's a slight API difference; additionally, it exposes a method for altering the internal queue class used. For BC purposes, it makes sense to keep both, though we can likely deprecate PriorityQueue when we release 2.6 with the new implementation.
I added a new Stdlib's priority queue implementation based on my FastPriorityQueue project.
The class
Zend\Stdlib\FastrPriorityQueue
implements an efficient integer priority queue in pure PHP. This class acts like a queue, removing the elements using the extract() function, and it acts like an Iterator, without removing the elements using a loop, i.e. foreach.The performance of this new class are very good, compared with
Zend\Stdlib\SplPriorityQueue
andZend\Stdlib\PriorityQueue
. I added a benchmark test in the /benchmark folder, using athletic.Here the results of a test using an Intel Core i5-2500 at 3.30GHz with 8 Gb of RAM running Ubuntu Linux 14.04 and PHP 5.5.9: