Created
February 2, 2014 17:36
-
-
Save guilhermeblanco/8771913 to your computer and use it in GitHub Desktop.
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
root@mahem:/var/www/doctrine# hhvm spl_priotity_queue.php | |
HipHop Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function insert() on a non-object' in : | |
Stack trace: | |
#0 /var/www/doctrine/splpriotityqueue.php(30): SplPriorityQueue->insert() | |
#1 {main} |
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
<?php | |
class MyPriorityQueue extends \SplPriorityQueue | |
{ | |
public function __construct() | |
{ | |
$this->setExtractFlags(self::EXTR_DATA); | |
} | |
public function sort() | |
{ | |
$sortedList = array(); | |
while ($this->valid()) { | |
$sortedList[] = $this->extract(); | |
} | |
return array_reverse($sortedList); | |
} | |
} | |
$data = array( | |
array('test1', 1), | |
array('test3', 3), | |
array('test2', 2), | |
); | |
$queue = new MyPriorityQueue(); | |
foreach ($data as $entry) { | |
$queue->insert($entry[0], $entry[1]); | |
} | |
var_dump($queue->sort()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment