Skip to content

Instantly share code, notes, and snippets.

@guilhermeblanco
Created February 2, 2014 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermeblanco/8771913 to your computer and use it in GitHub Desktop.
Save guilhermeblanco/8771913 to your computer and use it in GitHub Desktop.
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}
<?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