This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partition the priority queue as an internal property of EventQueue
Allows non-destructive traversal of EventQueue by iterators. Add iterator test.
- Loading branch information
1 parent
0d40995
commit 9f8db09
Showing
4 changed files
with
94 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Phergie (http://phergie.org) | ||
* @copyright Copyright (c) 2008-2015 Phergie Development Team (http://phergie.org) | ||
* @license http://phergie.org/license Simplified BSD License | ||
* @package Phergie\Irc\Bot\React | ||
*/ | ||
|
||
namespace Phergie\Irc\Bot\React; | ||
|
||
/** | ||
* Implementation of SplPriorityQueue specifically for internal use within | ||
* the EventQueue class. | ||
* | ||
* @category Phergie | ||
* @package Phergie\Irc\Bot\React | ||
*/ | ||
class EventQueueInternal extends \SplPriorityQueue | ||
{ | ||
/** | ||
* Overrides native default comparison logic to assign higher priority to | ||
* events inserted earlier. | ||
* | ||
* @param \Phergie\Irc\Bot\React\EventQueuePriority $priority1 | ||
* @param \Phergie\Irc\Bot\React\EventQueuePriority $priority2 | ||
* @return int | ||
*/ | ||
public function compare($priority1, $priority2) | ||
{ | ||
if (!$priority1 instanceof EventQueuePriority || !$priority2 instanceof EventQueuePriority) { | ||
return parent::compare($priority1, $priority2); | ||
} | ||
|
||
$priority = $priority1->value - $priority2->value; | ||
if (!$priority) { | ||
$priority = $priority2->timestamp - $priority1->timestamp; | ||
} | ||
return $priority; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters