|
SPL-StandardPHPLibrary
|


Public Member Functions | |
| bottom () | |
| count () | |
| current () | |
| dequeue () | |
| enqueue ($data) | |
| getIteratorMode () | |
| isEmpty () | |
| key () | |
| next () | |
| offsetExists ($offset) | |
| offsetGet ($offset) | |
| offsetSet ($offset, $value) | |
| offsetUnset ($offset) | |
| pop () | |
| push ($data) | |
| rewind () | |
| setIteratorMode ($mode) | |
| shift () | |
| top () | |
| unshift ($data) | |
| valid () | |
Public Attributes | |
| const | IT_MODE_DELETE = 0x00000001 |
| const | IT_MODE_FIFO = 0x00000000 |
| const | IT_MODE_KEEP = 0x00000000 |
| const | IT_MODE_LIFO = 0x00000002 |
Protected Attributes | |
| $_it_mode = parent::IT_MODE_FIFO | |
| $_it_pos = 0 | |
| $_llist = array() | |
Implementation of a Queue through a DoublyLinkedList.
As SplQueue extends SplDoublyLinkedList, unshift() and pop() are still available even though they don't make much sense for a queue. For convenience, two aliases are available:
The SplQueue class provides the main functionalities of a queue implemented using a doubly linked list (DLL).
Definition at line 25 of file splqueue.inc.
| SplDoublyLinkedList::bottom | ( | ) | [inherited] |
Definition at line 97 of file spldoublylinkedlist.inc.
{
return reset($this->_llist);
}
| SplDoublyLinkedList::count | ( | ) | [inherited] |
Implements Countable.
Definition at line 104 of file spldoublylinkedlist.inc.
Referenced by SplDoublyLinkedList\isEmpty(), SplDoublyLinkedList\offsetGet(), SplDoublyLinkedList\offsetSet(), SplDoublyLinkedList\offsetUnset(), SplDoublyLinkedList\pop(), SplDoublyLinkedList\rewind(), and SplDoublyLinkedList\shift().
{
return count($this->_llist);
}
| SplDoublyLinkedList::current | ( | ) | [inherited] |
Implements Iterator.
Definition at line 170 of file spldoublylinkedlist.inc.
{
return $this->_llist[$this->_it_pos];
}
| SplQueue::dequeue | ( | ) |
Definition at line 55 of file splqueue.inc.
References SplDoublyLinkedList\shift().
{
return parent::shift();
}

| SplQueue::enqueue | ( | $ | data | ) |
Pushes an element at the end of the queue.
| $data | variable to add to the queue. |
Definition at line 65 of file splqueue.inc.
References SplDoublyLinkedList\push().
{
return parent::push($data);
}

| SplDoublyLinkedList::getIteratorMode | ( | ) | [inherited] |
Definition at line 138 of file spldoublylinkedlist.inc.
{
return $this->_it_mode;
}
| SplDoublyLinkedList::isEmpty | ( | ) | [inherited] |
Definition at line 111 of file spldoublylinkedlist.inc.
References SplDoublyLinkedList\count().
{
return ($this->count() == 0);
}

| SplDoublyLinkedList::key | ( | ) | [inherited] |
Implements Iterator.
Definition at line 163 of file spldoublylinkedlist.inc.
{
return $this->_it_pos;
}
| SplDoublyLinkedList::next | ( | ) | [inherited] |
Forward to next element.
Implements Iterator.
Definition at line 177 of file spldoublylinkedlist.inc.
References SplDoublyLinkedList\pop(), and SplDoublyLinkedList\shift().
{
if ($this->_it_mode & self::IT_MODE_LIFO) {
if ($this->_it_mode & self::IT_MODE_DELETE) {
$this->pop();
}
$this->_it_pos--;
} else {
if ($this->_it_mode & self::IT_MODE_DELETE) {
$this->shift();
} else {
$this->_it_pos++;
}
}
}

| SplDoublyLinkedList::offsetExists | ( | $ | offset | ) | [inherited] |
| $offset | The offset |
| OutOfRangeException | If the offset is either invalid or out of range. |
Implements ArrayAccess.
Definition at line 199 of file spldoublylinkedlist.inc.
{
if (!is_numeric($offset)) {
throw new OutOfRangeException("Offset invalid or out of range");
} else {
return array_key_exists($offset, $this->_llist);
}
}
| SplDoublyLinkedList::offsetGet | ( | $ | offset | ) | [inherited] |
| $offset | The offset |
| OutOfRangeException | If the offset is either invalid or out of range. |
Implements ArrayAccess.
Definition at line 214 of file spldoublylinkedlist.inc.
References SplDoublyLinkedList\count().
{
if ($this->_it_mode & self::IT_MODE_LIFO) {
$realOffset = count($this->_llist)-$offset;
} else {
$realOffset = $offset;
}
if (!is_numeric($offset) || !array_key_exists($realOffset, $this->_llist)) {
throw new OutOfRangeException("Offset invalid or out of range");
} else {
return $this->_llist[$realOffset];
}
}

| SplDoublyLinkedList::offsetSet | ( | $ | offset, |
| $ | value | ||
| ) | [inherited] |
Defines the data at a certain offset in the DLL.
| $offset | The offset |
| $value | New value |
| OutOfRangeException | If the offset is either invalid or out of range. |
Implements ArrayAccess.
Definition at line 236 of file spldoublylinkedlist.inc.
References SplDoublyLinkedList\count(), and SplDoublyLinkedList\push().
{
if ($offset === null) {
return $this->push($value);
}
if ($this->_it_mode & self::IT_MODE_LIFO) {
$realOffset = count($this->_llist)-$offset;
} else {
$realOffset = $offset;
}
if (!is_numeric($offset) || !array_key_exists($realOffset, $this->_llist)) {
throw new OutOfRangeException("Offset invalid or out of range");
} else {
$this->_llist[$realOffset] = $value;
}
}

| SplDoublyLinkedList::offsetUnset | ( | $ | offset | ) | [inherited] |
Unsets the element at a certain offset in the DLL.
| $offset | The offset |
| OutOfRangeException | If the offset is either invalid or out of range. |
Implements ArrayAccess.
Definition at line 261 of file spldoublylinkedlist.inc.
References SplDoublyLinkedList\count().
{
if ($this->_it_mode & self::IT_MODE_LIFO) {
$realOffset = count($this->_llist)-$offset;
} else {
$realOffset = $offset;
}
if (!is_numeric($offset) || !array_key_exists($realOffset, $this->_llist)) {
throw new OutOfRangeException("Offset invalid or out of range");
} else {
array_splice($this->_llist, $realOffset, 1);
}
}

| SplDoublyLinkedList::pop | ( | ) | [inherited] |
| RuntimeException | If the datastructure is empty. |
Definition at line 51 of file spldoublylinkedlist.inc.
References SplDoublyLinkedList\count().
Referenced by SplDoublyLinkedList\next().
{
if (count($this->_llist) == 0) {
throw new RuntimeException("Can't pop from an empty datastructure");
}
return array_pop($this->_llist);
}

| SplDoublyLinkedList::push | ( | $ | data | ) | [inherited] |
Pushes an element to the end of the DLL.
| $data | variable to add to the DLL. |
Definition at line 73 of file spldoublylinkedlist.inc.
Referenced by enqueue(), and SplDoublyLinkedList\offsetSet().
{
array_push($this->_llist, $data);
return true;
}
| SplDoublyLinkedList::rewind | ( | ) | [inherited] |
Rewind to top iterator as set in constructor.
Implements Iterator.
Definition at line 145 of file spldoublylinkedlist.inc.
References SplDoublyLinkedList\count().
{
if ($this->_it_mode & self::IT_MODE_LIFO) {
$this->_it_pos = count($this->_llist)-1;
} else {
$this->_it_pos = 0;
}
}

| SplQueue::setIteratorMode | ( | $ | mode | ) |
Changes the iteration mode.
There are two orthogonal sets of modes that can be set:
The default mode is 0 : SplDoublyLnkedList::IT_MODE_LIFO | SplDoublyLnkedList::IT_MODE_KEEP
| $mode | New mode of iteration |
| RuntimeException | If the new mode affects the iteration's direction. |
Reimplemented from SplDoublyLinkedList.
Definition at line 42 of file splqueue.inc.
{
if ($mode & parent::IT_MODE_LIFO === parent::IT_MODE_LIFO) {
throw new RuntimeException("Iterators' LIFO/FIFO modes for SplStack/SplQueue objects are frozen");
}
$this->_it_mode = $mode;
}
| SplDoublyLinkedList::shift | ( | ) | [inherited] |
| RuntimeException | If the datastructure is empty. |
Definition at line 62 of file spldoublylinkedlist.inc.
References SplDoublyLinkedList\count().
Referenced by dequeue(), and SplDoublyLinkedList\next().
{
if (count($this->_llist) == 0) {
throw new RuntimeException("Can't shift from an empty datastructure");
}
return array_shift($this->_llist);
}

| SplDoublyLinkedList::top | ( | ) | [inherited] |
Definition at line 90 of file spldoublylinkedlist.inc.
{
return end($this->_llist);
}
| SplDoublyLinkedList::unshift | ( | $ | data | ) | [inherited] |
Adds an element to the beginning of the DLL.
| $data | variable to add to the DLL. |
Definition at line 82 of file spldoublylinkedlist.inc.
{
array_unshift($this->_llist, $data);
return true;
}
| SplDoublyLinkedList::valid | ( | ) | [inherited] |
Implements Iterator.
Definition at line 156 of file spldoublylinkedlist.inc.
{
return array_key_exists($this->_it_pos, $this->_llist);
}
SplQueue::$_it_mode = parent::IT_MODE_FIFO [protected] |
Reimplemented from SplDoublyLinkedList.
Definition at line 27 of file splqueue.inc.
SplDoublyLinkedList::$_it_pos = 0 [protected, inherited] |
Definition at line 26 of file spldoublylinkedlist.inc.
SplDoublyLinkedList::$_llist = array() [protected, inherited] |
Definition at line 24 of file spldoublylinkedlist.inc.
const SplDoublyLinkedList::IT_MODE_DELETE = 0x00000001 [inherited] |
const SplDoublyLinkedList::IT_MODE_FIFO = 0x00000000 [inherited] |
const SplDoublyLinkedList::IT_MODE_KEEP = 0x00000000 [inherited] |
const SplDoublyLinkedList::IT_MODE_LIFO = 0x00000002 [inherited] |
1.7.5.1