final 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.

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

void
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

The number of values for which capacity should be allocated. Capacity will stay the same if this value is less than or equal to the current capacity. Capacity will always be rounded up to the nearest power of 2.

Return Value

void

int capacity()

Returns the current capacity

Return Value

int

The current capacity.

void clear()

Removes all values from the collection.

Return Value

void

Collection copy()

Returns a shallow copy of the collection.

Return Value

Collection

Returns a shallow copy of the collection.

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

Returns true if the collection is empty, false otherwise.

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

void push(TValue $value, int $priority)

Pushes a value with a given priority into the queue.

Parameters

TValue $value

The value to push into the queue.

int $priority

The priority associated with the value.

Return Value

void

No value is returned.

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.