|
SPL-StandardPHPLibrary
|


Public Member Functions | |
| bottom () | |
| count () | |
| current () | |
| 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 = 0 | |
| $_it_pos = 0 | |
| $_llist = array() | |
Doubly Linked List.
The SplDoublyLinkedList class provides the main functionalities of a doubly linked list (DLL).
Definition at line 22 of file spldoublylinkedlist.inc.
| SplDoublyLinkedList::bottom | ( | ) |
Definition at line 97 of file spldoublylinkedlist.inc.
{
return reset($this->_llist);
}
| SplDoublyLinkedList::count | ( | ) |
Implements Countable.
Definition at line 104 of file spldoublylinkedlist.inc.
Referenced by isEmpty(), offsetGet(), offsetSet(), offsetUnset(), pop(), rewind(), and shift().
{
return count($this->_llist);
}
| SplDoublyLinkedList::current | ( | ) |
Implements Iterator.
Definition at line 170 of file spldoublylinkedlist.inc.
{
return $this->_llist[$this->_it_pos];
}
| SplDoublyLinkedList::getIteratorMode | ( | ) |
Definition at line 138 of file spldoublylinkedlist.inc.
{
return $this->_it_mode;
}
| SplDoublyLinkedList::isEmpty | ( | ) |
Definition at line 111 of file spldoublylinkedlist.inc.
References count().
{
return ($this->count() == 0);
}

| SplDoublyLinkedList::key | ( | ) |
Implements Iterator.
Definition at line 163 of file spldoublylinkedlist.inc.
{
return $this->_it_pos;
}
| SplDoublyLinkedList::next | ( | ) |
Forward to next element.
Implements Iterator.
Definition at line 177 of file spldoublylinkedlist.inc.
References pop(), and 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 | ) |
| $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 | ) |
| $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 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 | ||
| ) |
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 count(), and 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 | ) |
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 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 | ( | ) |
| RuntimeException | If the datastructure is empty. |
Definition at line 51 of file spldoublylinkedlist.inc.
References count().
Referenced by next().
{
if (count($this->_llist) == 0) {
throw new RuntimeException("Can't pop from an empty datastructure");
}
return array_pop($this->_llist);
}

| SplDoublyLinkedList::push | ( | $ | data | ) |
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 SplQueue\enqueue(), and offsetSet().
{
array_push($this->_llist, $data);
return true;
}
| SplDoublyLinkedList::rewind | ( | ) |
Rewind to top iterator as set in constructor.
Implements Iterator.
Definition at line 145 of file spldoublylinkedlist.inc.
References count().
{
if ($this->_it_mode & self::IT_MODE_LIFO) {
$this->_it_pos = count($this->_llist)-1;
} else {
$this->_it_pos = 0;
}
}

| SplDoublyLinkedList::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_FIFO | SplDoublyLnkedList::IT_MODE_KEEP
| $mode | new mode of iteration |
Reimplemented in SplQueue, and SplStack.
Definition at line 130 of file spldoublylinkedlist.inc.
{
$this->_it_mode = $mode;
}
| SplDoublyLinkedList::shift | ( | ) |
| RuntimeException | If the datastructure is empty. |
Definition at line 62 of file spldoublylinkedlist.inc.
References count().
Referenced by SplQueue\dequeue(), and next().
{
if (count($this->_llist) == 0) {
throw new RuntimeException("Can't shift from an empty datastructure");
}
return array_shift($this->_llist);
}

| SplDoublyLinkedList::top | ( | ) |
Definition at line 90 of file spldoublylinkedlist.inc.
{
return end($this->_llist);
}
| SplDoublyLinkedList::unshift | ( | $ | data | ) |
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 | ( | ) |
Implements Iterator.
Definition at line 156 of file spldoublylinkedlist.inc.
{
return array_key_exists($this->_it_pos, $this->_llist);
}
SplDoublyLinkedList::$_it_mode = 0 [protected] |
Reimplemented in SplQueue, and SplStack.
Definition at line 25 of file spldoublylinkedlist.inc.
SplDoublyLinkedList::$_it_pos = 0 [protected] |
Definition at line 26 of file spldoublylinkedlist.inc.
SplDoublyLinkedList::$_llist = array() [protected] |
Definition at line 24 of file spldoublylinkedlist.inc.
| const SplDoublyLinkedList::IT_MODE_DELETE = 0x00000001 |
| const SplDoublyLinkedList::IT_MODE_FIFO = 0x00000000 |
| const SplDoublyLinkedList::IT_MODE_KEEP = 0x00000000 |
| const SplDoublyLinkedList::IT_MODE_LIFO = 0x00000002 |
1.7.5.1