function TimerQueue::heapifyDown
Parameters
int $node Rebuild the data array from the given node downward.:
1 call to TimerQueue::heapifyDown()
- TimerQueue::removeAndRebuild in vendor/
revolt/ event-loop/ src/ EventLoop/ Internal/ TimerQueue.php
File
-
vendor/
revolt/ event-loop/ src/ EventLoop/ Internal/ TimerQueue.php, line 104
Class
- TimerQueue
- Uses a binary tree stored in an array to implement a heap.
Namespace
Revolt\EventLoop\InternalCode
private function heapifyDown(int $node) : void {
$length = \count($this->callbacks);
while (($child = ($node << 1) + 1) < $length) {
if ($this->callbacks[$child]->expiration < $this->callbacks[$node]->expiration && ($child + 1 >= $length || $this->callbacks[$child]->expiration < $this->callbacks[$child + 1]->expiration)) {
// Left child is less than parent and right child.
$swap = $child;
}
elseif ($child + 1 < $length && $this->callbacks[$child + 1]->expiration < $this->callbacks[$node]->expiration) {
// Right child is less than parent and left child.
$swap = $child + 1;
}
else {
// Left and right child are greater than parent.
break;
}
$this->swap($node, $swap);
$node = $swap;
}
}