The LinkedList class

(Available since version 1.0)

Introduction

The LinkedList class provides the main functionalities of a singly linked list.

It provides the interface as SplDoublyLinkedList but doesn't support LIFO mode. It can therefore be used as a drop-in replacement for SplDoublyLinkedList when you do not need LIFO.

On top of SplDoublyLinkedList's interface this class provides the following extra methods:

Please note that in practice many operations are more computationally expensive on singly linked lists relative to doubly linked lists. Additionally, this class is implemented in PHP whereas SplDoublyLinkedList is implemented in C, which is considerably faster.

This class is therefore not recommended for production code, and is provided for the sake of completeness and experimental purposes.

Class synopsis

SEIDS::LinkedLists::Singly::LinkedList implements ArrayAccess , Countable , Iterator {
/* Constants */
const int IT_MODE_DELETE = 1 ;
const int IT_MODE_KEEP = 0 ;
const int IT_MODE_LIFO = 2 ;
const int IT_MODE_FIFO = 0 ;
/* Properties */
protected SEIDS::LinkedLists::Singly::Item $first ;
protected SEIDS::LinkedLists::Singly::Item $last ;
protected SEIDS::LinkedLists::Singly::Item $current ;
protected int $current_key ;
protected SEIDS::LinkedLists::Singly::Item $worker ;
protected int $worker_key ;
protected int $size ;
protected int $flags ;
/* Methods */
public __construct ( void )
public void __clone ( void )
public void add ( int $index , mixed $newval )
public mixed bottom ( void )
public int count ( void )
public mixed current ( void )
public int getIteratorMode ( void )
public bool isEmpty ( void )
public mixed key ( void )
public void move ( int $offset_from , int $offset_to )
public void next ( void )
public bool offsetExists ( int $index )
public mixed offsetGet ( int $index )
public void offsetSet ( int $index , mixed $newval )
public void offsetUnset ( int $index )
public mixed pop ( void )
public void prev ( void )
public bool push ( mixed $value )
public mixed remove ( int $offset )
public void rewind ( void )
public string serialize ( void )
public int setIteratorMode ( int $mode )
public mixed shift ( void )
public mixed top ( void )
public void unserialize ( string $serialized )
public bool unshift ( mixed $value )
public bool valid ( void )
protected void moveToOffset ( int $offset )
}

Predefined Constants

LinkedList::IT_MODE_DELETE

(1) Flag for deleting whilst iterating.

LinkedList::IT_MODE_KEEP

(0) Absence of flag for deleting whilst iterating.

LinkedList::IT_MODE_LIFO

(2) Flag for Last In First Out mode.

LinkedList::IT_MODE_FIFO

(0) Absence of flag for Last In First Out mode.

Properties

first

The first item in the list.

last

The last item in the list.

current

The current item (when iterating).

current_key

The index of the current item.

worker

The last item the class 'worked' on.

worker_key

The index of the last item the class 'worked' on.

size

The number of items in the list.

flags

The iteration mode.

Table of Contents

To Top