(Available since version 1.0)
PriorityQueue::update — Updates a node in the queue to a new priority
Updates a node in the heap with the value,
value
, to a new priority,
priority
.
If two nodes in the heap have the same value then only one will be changed.
value
The value to be updated.
priority
The new priority.
No value is returned.
Throws SEIDS::Heaps::UpdateException when
value1
is not in the heap.
Example #1 PriorityQueue::update example (using a pairing heap)
<?php
require 'vendor/autoload.php'; // A PSR-4 or PSR-0 autoloader
use SEIDS\Heaps\Pairing\PriorityQueue;
$q = new PriorityQueue();
$q->insert('you', 9);
$q->insert('never', 7);
$q->insert('gonna', 5);
$q->insert('give', 3);
$q->insert('up', 1);
$q2 = clone $q;
$q->update('you', 2);
foreach ($q2 as $v) {
var_dump($v);
}
echo "\n";
foreach ($q as $v) {
var_dump($v);
}
?>
The above example will output:
string(3) "you" string(5) "never" string(5) "gonna" string(4) "give" string(2) "up" string(5) "never" string(5) "gonna" string(4) "give" string(3) "you" string(2) "up"