You are here

public function PriorityQueue::remove in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-stdlib/src/PriorityQueue.php \Zend\Stdlib\PriorityQueue::remove()

Remove an item from the queue

This is different than {@link extract()}; its purpose is to dequeue an item.

This operation is potentially expensive, as it requires re-initialization and re-population of the inner queue.

Note: this removes the first item matching the provided item found. If the same item has been added multiple times, it will not remove other instances.

Parameters

mixed $datum:

Return value

bool False if the item was not found, true otherwise.

File

vendor/zendframework/zend-stdlib/src/PriorityQueue.php, line 89

Class

PriorityQueue
Re-usable, serializable priority queue implementation

Namespace

Zend\Stdlib

Code

public function remove($datum) {
  $found = false;
  foreach ($this->items as $key => $item) {
    if ($item['data'] === $datum) {
      $found = true;
      break;
    }
  }
  if ($found) {
    unset($this->items[$key]);
    $this->queue = null;
    if (!$this
      ->isEmpty()) {
      $queue = $this
        ->getQueue();
      foreach ($this->items as $item) {
        $queue
          ->insert($item['data'], $item['priority']);
      }
    }
    return true;
  }
  return false;
}