-
Notifications
You must be signed in to change notification settings - Fork 76
Added the FastPriorityQueue implementation #19
Added the FastPriorityQueue implementation #19
Conversation
Does this have the same functionality as |
@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 |
|
public function insert($value, $priority) | ||
{ | ||
if (!is_int($priority) || $priority < 1) { | ||
throw new Exception\InvalidArgumentException("The priority must be a positive integer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a BC break, and won't work with the current MVC; we often use negative priorities to indicate items that should run later (recall: high positive priority === run earlier, low negative priority === run later). We need to accommodate that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I already fixed this.
Added the FastPriorityQueue implementation
Added the FastPriorityQueue implementation
{ | ||
const EXTR_DATA = 0x00000001; | ||
const EXTR_PRIORITY = 0x00000002; | ||
const EXTR_BOTH = 0x00000003; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Values are hexadecimal but as far as I see any scalar value could be valid, there is no binary operations and not its a bitmask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were written to match the SplPriorityQueue constants. They should
reflect those exactly.
On Sep 18, 2015 6:33 AM, "Maks3w" notifications@github.com wrote:
In src/FastPriorityQueue.php
#19 (comment)
:+use Countable;
+use Serializable;
+
+/**
- * This is an efficient implementation of an integer priority queue in PHP
- * This class acts like a queue with insert() and extract(), removing the
- * elements from the queue and it also acts like an Iterator without removing
- * the elements. This behaviour can be used in mixed scenarios with high
- * performance boost.
- */
+class FastPriorityQueue implements Iterator, Countable, Serializable
+{- const EXTR_DATA = 0x00000001;
- const EXTR_PRIORITY = 0x00000002;
- const EXTR_BOTH = 0x00000003;
Values are hexadecimal but as far as I see any scalar value could be
valid, there is no binary operations and not its a bitmask.—
Reply to this email directly or view it on GitHub
https://github.com/zendframework/zend-stdlib/pull/19/files#r39845972.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the constant then?
const EXTR_DATA = SplPriorityQueue::EXTR_DATA;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense; open a pull request for the change, please.
On Sep 18, 2015 7:39 AM, "Maks3w" notifications@github.com wrote:
In src/FastPriorityQueue.php
#19 (comment)
:+use Countable;
+use Serializable;
+
+/**
- * This is an efficient implementation of an integer priority queue in PHP
- * This class acts like a queue with insert() and extract(), removing the
- * elements from the queue and it also acts like an Iterator without removing
- * the elements. This behaviour can be used in mixed scenarios with high
- * performance boost.
- */
+class FastPriorityQueue implements Iterator, Countable, Serializable
+{- const EXTR_DATA = 0x00000001;
- const EXTR_PRIORITY = 0x00000002;
- const EXTR_BOTH = 0x00000003;
Why not use the constant then?
const EXTR_DATA = SplPriorityQueue::EXTR_DATA;
—
Reply to this email directly or view it on GitHub
https://github.com/zendframework/zend-stdlib/pull/19/files#r39850085.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll, we could even go more far and remove the constants and use directly SplPriorityQueue constants
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: