DoubleEndedQueue
extends Queue
in package
implements
DoubleEndedQueueInterface
This class provides a basic implementation of `DoubleEndedQueueInterface`, to minimize the effort required to implement this interface.
Interfaces, Classes, Traits and Enums
- DoubleEndedQueueInterface
- A linear collection that supports element insertion and removal at both ends.
Table of Contents
- $data : array<string|int, mixed>
- The items of this array.
- $index : int
- The index of the head of the queue.
- $queueType : string
- The type of elements stored in this queue.
- $tail : int
- Index of the last element in the queue.
- __construct() : mixed
- Constructs a new array object.
- add() : bool
- Ensures that this queue contains the specified element.
- addFirst() : bool
- Ensures that the specified element is inserted at the front of this queue.
- addLast() : bool
- Ensures that the specified element in inserted at the end of this queue.
- clear() : void
- Removes all items from this array.
- count() : int
- Returns the number of items in this array.
- element() : mixed
- Retrieves, but does not remove, the head of this queue.
- firstElement() : mixed
- Retrieves, but does not remove, the head of this queue.
- getIterator() : ArrayIterator<mixed, mixed>
- Returns an iterator for this array.
- getType() : string
- Returns the type associated with this queue.
- isEmpty() : bool
- Returns `true` if this array is empty.
- lastElement() : mixed
- Retrieves, but does not remove, the tail of this queue.
- offer() : bool
- Inserts the specified element into this queue.
- offerFirst() : bool
- Inserts the specified element at the front this queue.
- offerLast() : bool
- Inserts the specified element at the end this queue.
- offsetExists() : bool
- Returns `true` if the given offset exists in this array.
- offsetGet() : mixed|null
- Returns the value at the specified offset.
- offsetSet() : void
- Sets the given value to the given offset in the queue.
- offsetUnset() : void
- Removes the given offset and its value from the array.
- peek() : mixed|null
- Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty.
- peekFirst() : mixed|null
- Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty.
- peekLast() : mixed|null
- Retrieves, but does not remove, the tail of this queue, or returns `null` if this queue is empty.
- poll() : mixed|null
- Retrieves and removes the head of this queue, or returns `null` if this queue is empty.
- pollFirst() : mixed|null
- Retrieves and removes the head of this queue, or returns `null` if this queue is empty.
- pollLast() : mixed|null
- Retrieves and removes the tail of this queue, or returns `null` if this queue is empty.
- remove() : mixed
- Retrieves and removes the head of this queue.
- removeFirst() : mixed
- Retrieves and removes the head of this queue.
- removeLast() : mixed
- Retrieves and removes the tail of this queue.
- serialize() : string
- Returns a serialized string representation of this array object.
- toArray() : array<string|int, mixed>
- Returns a native PHP array representation of this array object.
- unserialize() : void
- Converts a serialized string representation into an instance object.
- checkType() : bool
- Returns `true` if value is of the specified type.
- toolValueToString() : string
- Returns a string representation of the value.
Properties
$data
The items of this array.
protected
array<string|int, mixed>
$data
= []
$index
The index of the head of the queue.
protected
int
$index
= 0
$queueType
The type of elements stored in this queue.
private
string
$queueType
A queue's type is immutable once it is set. For this reason, this property is set private.
$tail
Index of the last element in the queue.
private
int
$tail
= -1
Methods
__construct()
Constructs a new array object.
public
__construct([array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string|int, mixed> = []
-
The initial items to add to this array.
Return values
mixed —add()
Ensures that this queue contains the specified element.
public
add(mixed $element) : bool
This method differs from offer()
only in that it throws an exception if
it cannot add the element to the queue.
Parameters
- $element : mixed
-
The element to add to this queue.
Tags
Return values
bool —true
if this queue changed as a result of the call.
addFirst()
Ensures that the specified element is inserted at the front of this queue.
public
addFirst(mixed $element) : bool
Parameters
- $element : mixed
-
The element to add to this queue.
Tags
Return values
bool —true
if this queue changed as a result of the call.
addLast()
Ensures that the specified element in inserted at the end of this queue.
public
addLast(mixed $element) : bool
Parameters
- $element : mixed
-
The element to add to this queue.
Tags
Return values
bool —true
if this queue changed as a result of the call.
clear()
Removes all items from this array.
public
clear() : void
Return values
void —count()
Returns the number of items in this array.
public
count() : int
Tags
Return values
int —element()
Retrieves, but does not remove, the head of this queue.
public
element() : mixed
This method differs from peek()
only in that it throws an exception if
this queue is empty.
Tags
Return values
mixed —the head of this queue.
firstElement()
Retrieves, but does not remove, the head of this queue.
public
firstElement() : mixed
This method differs from peekFirst()
only in that it throws an
exception if this queue is empty.
Tags
Return values
mixed —the head of this queue.
getIterator()
Returns an iterator for this array.
public
getIterator() : ArrayIterator<mixed, mixed>
Tags
Return values
ArrayIterator<mixed, mixed> —getType()
Returns the type associated with this queue.
public
getType() : string
Return values
string —isEmpty()
Returns `true` if this array is empty.
public
isEmpty() : bool
Return values
bool —lastElement()
Retrieves, but does not remove, the tail of this queue.
public
lastElement() : mixed
This method differs from peekLast()
only in that it throws an exception
if this queue is empty.
Tags
Return values
mixed —the tail of this queue.
offer()
Inserts the specified element into this queue.
public
offer(mixed $element) : bool
This method differs from add()
only in that it does not throw an
exception if it cannot add the element to the queue.
Parameters
- $element : mixed
-
The element to add to this queue.
Tags
Return values
bool —true
if the element was added to this queue, else false
.
offerFirst()
Inserts the specified element at the front this queue.
public
offerFirst(mixed $element) : bool
Parameters
- $element : mixed
-
The element to add to this queue.
Tags
Return values
bool —true
if the element was added to this queue, else false
.
offerLast()
Inserts the specified element at the end this queue.
public
offerLast(mixed $element) : bool
Parameters
- $element : mixed
-
The element to add to this queue.
Tags
Return values
bool —true
if the element was added to this queue, else false
.
offsetExists()
Returns `true` if the given offset exists in this array.
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
-
The offset to check.
Tags
Return values
bool —offsetGet()
Returns the value at the specified offset.
public
offsetGet(mixed $offset) : mixed|null
Parameters
- $offset : mixed
-
The offset for which a value should be returned.
Tags
Return values
mixed|null —the value stored at the offset, or null if the offset does not exist.
offsetSet()
Sets the given value to the given offset in the queue.
public
offsetSet(mixed|null $offset, mixed $value) : void
Since arbitrary offsets may not be manipulated in a queue, this method
serves only to fulfill the ArrayAccess
interface requirements. It is
invoked by other operations when adding values to the queue.
Parameters
- $offset : mixed|null
-
The offset is ignored and is treated as
null
. - $value : mixed
-
The value to set at the given offset.
Tags
Return values
void —offsetUnset()
Removes the given offset and its value from the array.
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
-
The offset to remove from the array.
Tags
Return values
void —peek()
Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty.
public
peek() : mixed|null
Tags
Return values
mixed|null —the head of this queue, or null
if this queue is empty.
peekFirst()
Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty.
public
peekFirst() : mixed|null
Tags
Return values
mixed|null —the head of this queue, or null
if this queue is empty.
peekLast()
Retrieves, but does not remove, the tail of this queue, or returns `null` if this queue is empty.
public
peekLast() : mixed|null
Tags
Return values
mixed|null —the tail of this queue, or null
if this queue is empty
poll()
Retrieves and removes the head of this queue, or returns `null` if this queue is empty.
public
poll() : mixed|null
Tags
Return values
mixed|null —the head of this queue, or null
if this queue is empty.
pollFirst()
Retrieves and removes the head of this queue, or returns `null` if this queue is empty.
public
pollFirst() : mixed|null
Tags
Return values
mixed|null —the head of this queue, or null
if this queue is empty.
pollLast()
Retrieves and removes the tail of this queue, or returns `null` if this queue is empty.
public
pollLast() : mixed|null
Tags
Return values
mixed|null —the tail of this queue, or null
if this queue is empty.
remove()
Retrieves and removes the head of this queue.
public
remove() : mixed
This method differs from poll()
only in that it throws an exception if
this queue is empty.
Tags
Return values
mixed —the head of this queue.
removeFirst()
Retrieves and removes the head of this queue.
public
removeFirst() : mixed
This method differs from pollFirst()
only in that it throws an
exception if this queue is empty.
Tags
Return values
mixed —the head of this queue.
removeLast()
Retrieves and removes the tail of this queue.
public
removeLast() : mixed
This method differs from pollLast()
only in that it throws an exception
if this queue is empty.
Tags
Return values
mixed —the tail of this queue.
serialize()
Returns a serialized string representation of this array object.
public
serialize() : string
Tags
Return values
string —a PHP serialized string.
toArray()
Returns a native PHP array representation of this array object.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —unserialize()
Converts a serialized string representation into an instance object.
public
unserialize(string $serialized) : void
Parameters
- $serialized : string
-
A PHP serialized string to unserialize.
Tags
Return values
void —checkType()
Returns `true` if value is of the specified type.
protected
checkType(string $type, mixed $value) : bool
Parameters
- $type : string
-
The type to check the value against.
- $value : mixed
-
The value to check.
Return values
bool —toolValueToString()
Returns a string representation of the value.
protected
toolValueToString(mixed $value) : string
- null value:
'NULL'
- boolean:
'TRUE'
,'FALSE'
- array:
'Array'
- scalar: converted-value
- resource:
'(type resource #number)'
- object with
__toString()
: result of__toString()
- object DateTime: ISO 8601 date
- object:
'(className Object)'
- anonymous function: same as object
Parameters
- $value : mixed
-
the value to return as a string.