DoubleEndedQueue
extends Queue
in package
implements
DoubleEndedQueueInterface
This class provides a basic implementation of `DoubleEndedQueueInterface`, to minimize the effort required to implement this interface.
Tags
Interfaces, Classes, Traits and Enums
- DoubleEndedQueueInterface
- A linear collection that supports element insertion and removal at both ends.
Table of Contents
- $data : array<array-key, T>
- 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.
- __serialize() : array<array-key, T>
- Returns data suitable for PHP serialization.
- __unserialize() : void
- Adds unserialized data to the object.
- add() : bool
- Ensures that this queue contains the specified element (optional operation).
- addFirst() : bool
- Inserts the specified element at the front of this queue if it is possible to do so immediately without violating capacity restrictions.
- addLast() : bool
- Inserts the specified element at the end of this queue if it is possible to do so immediately without violating capacity restrictions.
- clear() : void
- Removes all items from this array.
- count() : int
- Returns the number of items in this array.
- element() : T
- Retrieves, but does not remove, the head of this queue.
- firstElement() : T
- Retrieves, but does not remove, the head of this queue.
- getIterator() : Traversable<array-key, T>
- 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() : T
- Retrieves, but does not remove, the tail of this queue.
- offer() : bool
- Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
- offerFirst() : bool
- Inserts the specified element at the front of this queue if it is possible to do so immediately without violating capacity restrictions.
- offerLast() : bool
- Inserts the specified element at the end of this queue if it is possible to do so immediately without violating capacity restrictions.
- offsetExists() : bool
- Returns `true` if the given offset exists in this array.
- offsetGet() : T|null
- Returns the value at the specified offset.
- offsetSet() : void
- Sets the given value to the given offset in the array.
- offsetUnset() : void
- Removes the given offset and its value from the array.
- peek() : T|null
- Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty.
- peekFirst() : T|null
- Retrieves, but does not remove, the head of this queue, or returns `null` if this queue is empty.
- peekLast() : T|null
- Retrieves, but does not remove, the tail of this queue, or returns `null` if this queue is empty.
- poll() : T|null
- Retrieves and removes the head of this queue, or returns `null` if this queue is empty.
- pollFirst() : T|null
- Retrieves and removes the head of this queue, or returns `null` if this queue is empty.
- pollLast() : T|null
- Retrieves and removes the tail of this queue, or returns `null` if this queue is empty.
- remove() : T
- Retrieves and removes the head of this queue.
- removeFirst() : T
- Retrieves and removes the head of this queue.
- removeLast() : T
- Retrieves and removes the tail of this queue.
- serialize() : string
- Returns a serialized string representation of this array object.
- toArray() : array<array-key, T>
- 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<array-key, T>
$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<array-key, T> $data = [] ]) : mixed
Parameters
- $data : array<array-key, T> = []
-
The initial items to add to this array.
Return values
mixed —__serialize()
Returns data suitable for PHP serialization.
public
__serialize() : array<array-key, T>
Tags
Return values
array<array-key, T> —__unserialize()
Adds unserialized data to the object.
public
__unserialize(array<array-key, T> $data) : void
Parameters
- $data : array<array-key, T>
Return values
void —add()
Ensures that this queue contains the specified element (optional operation).
public
add(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.
addFirst()
Inserts the specified element at the front of this queue if it is possible to do so immediately without violating capacity restrictions.
public
addFirst(mixed $element) : bool
Parameters
- $element : mixed
-
The element to add to the front of this queue.
Tags
Return values
bool —true
if this queue changed as a result of the call.
addLast()
Inserts the specified element at the end of this queue if it is possible to do so immediately without violating capacity restrictions.
public
addLast(mixed $element) : bool
Parameters
- $element : mixed
-
The element to add to the end of 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() : T
Tags
Return values
T —the head of this queue.
firstElement()
Retrieves, but does not remove, the head of this queue.
public
firstElement() : T
Tags
Return values
T —the head of this queue.
getIterator()
Returns an iterator for this array.
public
getIterator() : Traversable<array-key, T>
Tags
Return values
Traversable<array-key, T> —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() : T
Tags
Return values
T —the tail of this queue.
offer()
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
public
offer(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
.
offerFirst()
Inserts the specified element at the front of this queue if it is possible to do so immediately without violating capacity restrictions.
public
offerFirst(mixed $element) : bool
Parameters
- $element : mixed
-
The element to add to the front of 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 of this queue if it is possible to do so immediately without violating capacity restrictions.
public
offerLast(mixed $element) : bool
Parameters
- $element : mixed
-
The element to add to the end of 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(string|int $offset) : bool
Parameters
- $offset : string|int
-
The offset to check.
Tags
Return values
bool —offsetGet()
Returns the value at the specified offset.
public
offsetGet(string|int $offset) : T|null
Parameters
- $offset : string|int
-
The offset for which a value should be returned.
Tags
Return values
T|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 array.
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
-
The offset to set. If
null
, the value may be set at a numerically-indexed offset. - $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(string|int $offset) : void
Parameters
- $offset : string|int
-
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() : T|null
Tags
Return values
T|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() : T|null
Tags
Return values
T|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() : T|null
Tags
Return values
T|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() : T|null
Tags
Return values
T|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() : T|null
Tags
Return values
T|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() : T|null
Tags
Return values
T|null —the tail of this queue, or null
if this queue is empty.
remove()
Retrieves and removes the head of this queue.
public
remove() : T
Tags
Return values
T —the head of this queue.
removeFirst()
Retrieves and removes the head of this queue.
public
removeFirst() : T
Tags
Return values
T —the first element in this queue.
removeLast()
Retrieves and removes the tail of this queue.
public
removeLast() : T
Tags
Return values
T —the last element in 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<array-key, T>
Tags
Return values
array<array-key, T> —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.