DatenstrukturenInhaltsverzeichnis
SPL provides a set of standard datastructures. They are grouped here by their underlying implementation which usually defines their general field of application. Doubly Linked ListsA Doubly Linked List (DLL) is a list of nodes linked in both directions to each other. Iterator's operations, access to both ends, addition or removal of nodes have a cost of O(1) when the underlying structure is a DLL. It hence provides a decent implementation for stacks and queues.
HeapsHeaps are tree-like structures that follow the heap-property: each node is greater than or equal to its children, when compared using the implemented compare method which is global to the heap.
ArraysArrays are structures that store the data in a continuous way, accessible via indexes. Don't confuse them with PHP arrays: PHP arrays are in fact implemented as ordered hashtables.
MapA map is a datastructure holding key-value pairs. PHP arrays can be seen as maps from integers/strings to values. SPL provides a map from objects to data. This map can also be used as an object set.
The SplDoublyLinkedList classEinführungThe SplDoublyLinkedList class provides the main functionalities of a doubly linked list. KlassenbeschreibungSplDoublyLinkedList
class SplDoublyLinkedList
implements
Iterator
,
ArrayAccess
,
Countable
{
/* Methoden */
public __construct
( void
)
public void add
( mixed
$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 next
( void
)
public bool offsetExists
( mixed
$index
)
public mixed offsetGet
( mixed
$index
)
public void offsetSet
( mixed
$index
, mixed $newval
)
public void offsetUnset
( mixed
$index
)
public mixed pop
( void
)
public void prev
( void
)
public void push
( mixed
$value
)
public void rewind
( void
)
public string serialize
( void
)
public void setIteratorMode
( int
$mode
)
public mixed shift
( void
)
public mixed top
( void
)
public void unserialize
( string
$serialized
)
public void unshift
( mixed
$value
)
public bool valid
( void
)
}The SplStack classEinführungThe SplStack class provides the main functionalities of a stack implemented using a doubly linked list. KlassenbeschreibungSplStack
class SplStack
extends
SplDoublyLinkedList
implements
Iterator
,
ArrayAccess
,
Countable
{
/* Methoden */
__construct
( void
)
void setIteratorMode
( int
$mode
)/* Geerbte Methoden */
public void SplDoublyLinkedList::add
( mixed
$index
, mixed $newval
)
public mixed SplDoublyLinkedList::bottom
( void
)
public int SplDoublyLinkedList::count
( void
)
public mixed SplDoublyLinkedList::current
( void
)
public int SplDoublyLinkedList::getIteratorMode
( void
)
public bool SplDoublyLinkedList::isEmpty
( void
)
public mixed SplDoublyLinkedList::key
( void
)
public void SplDoublyLinkedList::next
( void
)
public bool SplDoublyLinkedList::offsetExists
( mixed
$index
)
public mixed SplDoublyLinkedList::offsetGet
( mixed
$index
)
public void SplDoublyLinkedList::offsetSet
( mixed
$index
, mixed $newval
)
public void SplDoublyLinkedList::offsetUnset
( mixed
$index
)
public mixed SplDoublyLinkedList::pop
( void
)
public void SplDoublyLinkedList::prev
( void
)
public void SplDoublyLinkedList::push
( mixed
$value
)
public void SplDoublyLinkedList::rewind
( void
)
public string SplDoublyLinkedList::serialize
( void
)
public void SplDoublyLinkedList::setIteratorMode
( int
$mode
)
public mixed SplDoublyLinkedList::shift
( void
)
public mixed SplDoublyLinkedList::top
( void
)
public void SplDoublyLinkedList::unserialize
( string
$serialized
)
public void SplDoublyLinkedList::unshift
( mixed
$value
)
public bool SplDoublyLinkedList::valid
( void
)
}The SplQueue classEinführungThe SplQueue class provides the main functionalities of a queue implemented using a doubly linked list. KlassenbeschreibungSplQueue
class SplQueue
extends
SplDoublyLinkedList
implements
Iterator
,
ArrayAccess
,
Countable
{
/* Methoden */
__construct
( void
)
mixed dequeue
( void
)
void enqueue
( mixed
$value
)
void setIteratorMode
( int
$mode
)/* Geerbte Methoden */
public void SplDoublyLinkedList::add
( mixed
$index
, mixed $newval
)
public mixed SplDoublyLinkedList::bottom
( void
)
public int SplDoublyLinkedList::count
( void
)
public mixed SplDoublyLinkedList::current
( void
)
public int SplDoublyLinkedList::getIteratorMode
( void
)
public bool SplDoublyLinkedList::isEmpty
( void
)
public mixed SplDoublyLinkedList::key
( void
)
public void SplDoublyLinkedList::next
( void
)
public bool SplDoublyLinkedList::offsetExists
( mixed
$index
)
public mixed SplDoublyLinkedList::offsetGet
( mixed
$index
)
public void SplDoublyLinkedList::offsetSet
( mixed
$index
, mixed $newval
)
public void SplDoublyLinkedList::offsetUnset
( mixed
$index
)
public mixed SplDoublyLinkedList::pop
( void
)
public void SplDoublyLinkedList::prev
( void
)
public void SplDoublyLinkedList::push
( mixed
$value
)
public void SplDoublyLinkedList::rewind
( void
)
public string SplDoublyLinkedList::serialize
( void
)
public void SplDoublyLinkedList::setIteratorMode
( int
$mode
)
public mixed SplDoublyLinkedList::shift
( void
)
public mixed SplDoublyLinkedList::top
( void
)
public void SplDoublyLinkedList::unserialize
( string
$serialized
)
public void SplDoublyLinkedList::unshift
( mixed
$value
)
public bool SplDoublyLinkedList::valid
( void
)
}The SplHeap classEinführungThe SplHeap class provides the main functionalities of a Heap. KlassenbeschreibungSplHeap
abstract class SplHeap
implements
Iterator
,
Countable
{
/* Methoden */
public __construct
( void
)
abstract protected int compare
( mixed
$value1
, mixed $value2
)
public int count
( void
)
public mixed current
( void
)
public mixed extract
( void
)
public void insert
( mixed
$value
)
public bool isEmpty
( void
)
public mixed key
( void
)
public void next
( void
)
public void recoverFromCorruption
( void
)
public void rewind
( void
)
public mixed top
( void
)
public bool valid
( void
)
}The SplMaxHeap classEinführungThe SplMaxHeap class provides the main functionalities of a heap, keeping the maximum on the top. KlassenbeschreibungSplMaxHeap
class SplMaxHeap
extends
SplHeap
implements
Iterator
,
Countable
{
/* Methoden */
protected int compare
( mixed
$value1
, mixed $value2
)/* Geerbte Methoden */
abstract protected int SplHeap::compare
( mixed
$value1
, mixed $value2
)
public int SplHeap::count
( void
)
public mixed SplHeap::current
( void
)
public mixed SplHeap::extract
( void
)
public void SplHeap::insert
( mixed
$value
)
public bool SplHeap::isEmpty
( void
)
public mixed SplHeap::key
( void
)
public void SplHeap::next
( void
)
public void SplHeap::recoverFromCorruption
( void
)
public void SplHeap::rewind
( void
)
public mixed SplHeap::top
( void
)
public bool SplHeap::valid
( void
)
}The SplMinHeap classEinführungThe SplMinHeap class provides the main functionalities of a heap, keeping the minimum on the top. KlassenbeschreibungSplMinHeap
class SplMinHeap
extends
SplHeap
implements
Iterator
,
Countable
{
/* Methoden */
protected int compare
( mixed
$value1
, mixed $value2
)/* Geerbte Methoden */
abstract protected int SplHeap::compare
( mixed
$value1
, mixed $value2
)
public int SplHeap::count
( void
)
public mixed SplHeap::current
( void
)
public mixed SplHeap::extract
( void
)
public void SplHeap::insert
( mixed
$value
)
public bool SplHeap::isEmpty
( void
)
public mixed SplHeap::key
( void
)
public void SplHeap::next
( void
)
public void SplHeap::recoverFromCorruption
( void
)
public void SplHeap::rewind
( void
)
public mixed SplHeap::top
( void
)
public bool SplHeap::valid
( void
)
}The SplPriorityQueue classEinführungThe SplPriorityQueue class provides the main functionalities of a prioritized queue, implemented using a max heap. KlassenbeschreibungSplPriorityQueue
class SplPriorityQueue
implements
Iterator
,
Countable
{
/* Methoden */
public __construct
( void
)
public int compare
( mixed
$priority1
, mixed $priority2
)
public int count
( void
)
public mixed current
( void
)
public mixed extract
( void
)
public void insert
( mixed
$value
, mixed $priority
)
public bool isEmpty
( void
)
public mixed key
( void
)
public void next
( void
)
public void recoverFromCorruption
( void
)
public void rewind
( void
)
public void setExtractFlags
( int
$flags
)
public mixed top
( void
)
public bool valid
( void
)
}The SplFixedArray classEinführungThe SplFixedArray class provides the main functionalities of array. The main differences between a SplFixedArray and a normal PHP array is that the SplFixedArray is of fixed length and allows only integers within the range as indexes. The advantage is that it allows a faster array implementation. KlassenbeschreibungSplFixedArray
class SplFixedArray
implements
Iterator
,
ArrayAccess
,
Countable
{
/* Methoden */
public __construct
([ int
$size = 0
] )
public int count
( void
)
public mixed current
( void
)
public static SplFixedArray fromArray
( array
$array
[, bool $save_indexes = true
] )
public int getSize
( void
)
public int key
( void
)
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 void rewind
( void
)
public int setSize
( int
$size
)
public array toArray
( void
)
public bool valid
( void
)
public void __wakeup
( void
)
}Beispiele
Beispiel #1 SplFixedArray usage example
<?phpDas oben gezeigte Beispiel erzeugt folgende Ausgabe: NULL int(2) string(3) "foo" RuntimeException: Index invalid or out of range RuntimeException: Index invalid or out of range RuntimeException: Index invalid or out of range The SplObjectStorage classEinführungThe SplObjectStorage class provides a map from objects to data or, by ignoring data, an object set. This dual purpose can be useful in many cases involving the need to uniquely identify objects. KlassenbeschreibungSplObjectStorage
class SplObjectStorage
implements
Countable
,
Iterator
,
Serializable
,
ArrayAccess
{
/* Methoden */
public void addAll
( SplObjectStorage
$storage
)
public void attach
( object
$object
[, mixed $data = NULL
] )
public bool contains
( object
$object
)
public int count
( void
)
public object current
( void
)
public void detach
( object
$object
)
public string getHash
( object
$object
)
public mixed getInfo
( void
)
public int key
( void
)
public void next
( void
)
public bool offsetExists
( object
$object
)
public mixed offsetGet
( object
$object
)
public void offsetSet
( object
$object
[, mixed $data = NULL
] )
public void offsetUnset
( object
$object
)
public void removeAll
( SplObjectStorage
$storage
)
public void removeAllExcept
( SplObjectStorage
$storage
)
public void rewind
( void
)
public string serialize
( void
)
public void setInfo
( mixed
$data
)
public void unserialize
( string
$serialized
)
public bool valid
( void
)
}Beispiele
Beispiel #1 SplObjectStorage as a set
<?phpDas oben gezeigte Beispiel erzeugt folgende Ausgabe: bool(true) bool(true) bool(false) bool(true) bool(false) bool(false) Beispiel #2 SplObjectStorage as a map
<?phpDas oben gezeigte Beispiel erzeugt folgende Ausgabe:
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
|