class PriorityQueue implements Collection (View source)

A PriorityQueue is very similar to a Queue. Values are pushed into the queue with an assigned priority, and the value with the highest priority will always be at the front of the queue.

Implemented using a max heap.

Constants

MIN_CAPACITY

Methods

int
count()

Count elements of an object

void
allocate(int $capacity)

Allocates enough memory for a required capacity

int
capacity()

Returns the current capacity

void
clear()

Removes all values from the collection.

TValue>
copy()

Returns a shallow copy of the collection.

getIterator()

No description

bool
isEmpty()

Returns whether the collection is empty.

TValue
peek()

Returns the value at the front of the queue, but does not remove it.

TValue
pop()

Removes and returns the value with the highest priority

push(TValue $value, int $priority)

Pushes a value with a given priority into the queue.

array
toArray()

Converts the collection to an array.

mixed
jsonSerialize()

Specify data which should be serialized to JSON

Details

int count()

Since: 5.1

Count elements of an object

Return Value

int

The custom count as an integer.

The return value is cast to an integer.

void allocate(int $capacity)

Allocates enough memory for a required capacity

Parameters

int $capacity

Return Value

void

int capacity()

Returns the current capacity

Return Value

int

void clear()

Removes all values from the collection.

Return Value

void

TValue> copy()

Returns a shallow copy of the collection.

Return Value

TValue>

Traversable getIterator()

No description

Return Value

Traversable

An instance of an object implementing Iterator or Traversable

bool isEmpty()

Returns whether the collection is empty.

Return Value

bool

TValue peek()

Returns the value at the front of the queue, but does not remove it.

Return Value

TValue

The value at the front of the queue.

Exceptions

UnderflowException

TValue pop()

Removes and returns the value with the highest priority

Return Value

TValue

The removed value which was at the front of the queue.

Exceptions

UnderflowException

push(TValue $value, int $priority)

Pushes a value with a given priority into the queue.

Parameters

TValue $value
int $priority

array toArray()

Converts the collection to an array.

Note: Casting to an array is not supported yet.

Return Value

array

An array containing all the values in the same order as the collection.

mixed jsonSerialize()

Since: 5.4

Specify data which should be serialized to JSON

Return Value

mixed

data which can be serialized by json_encode, which is a value of any type other than a resource.