class Queue implements Collection, ArrayAccess (View source)

A Queue is a “first in, first out” or “FIFO” collection that only allows access to the value at the front of the queue and iterates in that order, destructively.

Uses a Ds\Vector internally.

Methods

__construct(TValue> $values = [])

Creates a new instance, using either a traversable object or an array for the initial values.

allocate(int $capacity)

Ensures that enough memory is allocated for a required capacity. This removes the need to reallocate the internal as values are added.

int
capacity()

Returns the current capacity.

void
clear()

Removes all values from the queue.

int
count()

Count elements of an object

TValue>
copy()

Returns a shallow copy of the collection.

getIterator()

No description

bool
isEmpty()

Returns whether the collection is empty.

array
toArray()

Converts the collection to an array.

mixed
jsonSerialize()

Specify data which should be serialized to JSON

TValue
peek()

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

TValue
pop()

Removes and returns the value at the top of the queue.

push(TValue ...$values)

Pushes values onto the queue.

bool
offsetExists(TKey $offset)

No description

mixed
offsetGet(TKey $offset)

No description

void
offsetSet(TKey $offset, TValue $value)

No description

void
offsetUnset(TKey $offset)

No description

Details

__construct(TValue> $values = [])

Creates a new instance, using either a traversable object or an array for the initial values.

Parameters

TValue> $values

A traversable object or an array to use for the initial values.

allocate(int $capacity)

Ensures that enough memory is allocated for a required capacity. This removes the need to reallocate the internal as values are added.

Parameters

int $capacity

The number of values for which capacity should be allocated.

Note: Capacity will stay the same if this value is less than or equal to the current capacity.

int capacity()

Returns the current capacity.

Return Value

int

The current capacity.

void clear()

Removes all values from the queue.

Return Value

void

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.

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

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.

TValue peek()

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

Return Value

TValue

The value at the top of the queue.

Exceptions

UnderflowException

TValue pop()

Removes and returns the value at the top of the queue.

Return Value

TValue

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

Exceptions

UnderflowException

push(TValue ...$values)

Pushes values onto the queue.

Parameters

TValue ...$values

The values to push onto the queue.

bool offsetExists(TKey $offset)

No description

Parameters

TKey $offset

An offset to check for.

Return Value

bool

true on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

mixed offsetGet(TKey $offset)

No description

Parameters

TKey $offset

The offset to retrieve.

Return Value

mixed

Can return all value types.

void offsetSet(TKey $offset, TValue $value)

No description

Parameters

TKey $offset

The offset to assign the value to.

TValue $value

The value to set.

Return Value

void

void offsetUnset(TKey $offset)

No description

Parameters

TKey $offset

The offset to unset.

Return Value

void