note 92093 added to class.splheap
| From: | Anonymous at osu1 dot php dot net | Date: | Wed, 08 Jul 2009 14:48:01 +0000 |
| Subject: | note 92093 added to class.splheap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158061@lists.php.net to get a copy of this message | ||
<?php
class CallbackComparatorHeap extends SplHeap {
protected $callback;
public function __construct($callback) {
if (!is_callable($callback)) {
throw new InvalidArgumentException();
}
$this->callback = $callback;
}
public function compare($mixed1, $mixed2) {
return call_user_func($this->callback, $mixed1, $mixed2);
}
}
// max heap.
// or do b - a for a min heap
$heap = new CallbackComparatorHeap(function($a, $b) {
return $a['foo'] - $b['foo'];
});
$heap->insert(array('foo' => 9));
$heap->insert(array('foo' => 11));
$heap->insert(array('foo' => 2));
foreach ($heap as $node) {
echo $node['foo'];
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 76.14.51.84
----
Manual Page -- http://www.php.net/manual/en/class.splheap.php
Edit -- https://master.php.net/note/edit/92093
Del: integrated -- https://master.php.net/note/delete/92093/integrated
Del: useless -- https://master.php.net/note/delete/92093/useless
Del: bad code -- https://master.php.net/note/delete/92093/bad+code
Del: spam -- https://master.php.net/note/delete/92093/spam
Del: non-english -- https://master.php.net/note/delete/92093/non-english
Del: in docs -- https://master.php.net/note/delete/92093/in+docs
Del: other reasons-- https://master.php.net/note/delete/92093
Reject -- https://master.php.net/note/reject/92093
Search -- https://master.php.net/manage/user-notes.php