一、数据结构
1、SplDoublyLinkedList双向链表
百度百科定义双向链表为:双向链表也叫双链表,是链表的一种,它的每个数据结点中都有两个指针,分别指向直接后继和直接前驱。所以,从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点。一般我们都构造双向循环链表。
在手册中定义的SplDoublyLinkedList主要结构为:
SplDoublyLinkedList implements Iterator , ArrayAccess , Countable , Serializable {
/* 常量 */
const integer IT_MODE_LIFO = 2 ;
const integer IT_MODE_FIFO = 0 ;
const integer IT_MODE_DELETE = 1 ;
const integer IT_MODE_KEEP = 0 ;
/* 方法 */
public __construct ( void ) public add ( mixed $index , mixed $newval ) : void public bottom ( void ) : mixed public count ( void ) : int public current ( void ) : mixed public getIteratorMode ( void ) : int public isEmpty ( void ) : bool public key ( void ) : mixed public next ( void ) : void public offsetExists ( mixed $index ) : bool public offsetGet ( mixed $index ) : mixed public offsetSet ( mixed $index , mixed $newval ) : void public offsetUnset ( mixed $index ) : void public pop ( void ) : mixed public prev ( void ) : void public push ( mixed $value ) : void public rewind ( void ) : void public serialize ( void ) : string public setIteratorMode ( int $mode ) : void public shift ( void ) : mixed public top ( void ) : mixed public unserialize ( string $serialized ) : void public unshift ( mixed $value ) : void public valid ( void ) : bool }
测试及应用
2、SplStack
SplStack类通过使用一个双向链表来提供栈的主要功能, 继承自类SplDoublyLinkedList,栈(Stack)是一种特殊的线性表,因为它只能在线性表的一端进行插入或删除元素(即进栈和出栈)
SplStack extends SplDoublyLinkedList implements Iterator , ArrayAccess , Countable { /* 方法 */ __construct ( void ) setIteratorMode ( int $mode ) : void /* 继承的方法 */ public SplDoublyLinkedList::add ( mixed $index , mixed $newval ) : void public SplDoublyLinkedList::bottom ( void ) : mixed public SplDoublyLinkedList::count ( void ) : int public SplDoublyLinkedList::current ( void ) : mixed public SplDoublyLinkedList::getIteratorMode ( void ) : int public SplDoublyLinkedList::isEmpty ( void ) : bool public SplDoublyLinkedList::key ( void ) : mixed public SplDoublyLinkedList::next ( void ) : void public SplDoublyLinkedList::offsetExists ( mixed $index ) : bool public SplDoublyLinkedList::offsetGet ( mixed $index ) : mixed public SplDoublyLinkedList::offsetSet ( mixed $index , mixed $newval ) : void public SplDoublyLinkedList::offsetUnset ( mixed $index ) : void public SplDoublyLinkedList::pop ( void ) : mixed public SplDoublyLinkedList::prev ( void ) : void public SplDoublyLinkedList::push ( mixed $value ) : void public SplDoublyLinkedList::rewind ( void ) : void public SplDoublyLinkedList::serialize ( void ) : string public SplDoublyLinkedList::setIteratorMode ( int $mode ) : void public SplDoublyLinkedList::shift ( void ) : mixed public SplDoublyLinkedList::top ( void ) : mixed public SplDoublyLinkedList::unserialize ( string $serialized ) : void public SplDoublyLinkedList::unshift ( mixed $value ) : void public SplDoublyLinkedList::valid ( void ) : bool }
3、SplQueue
SplQueue类通过使用一个双向链表来提供队列的主要功能,继承自类SplDoublyLinkedList,队列(SplQueue) 就像我们生活中排队一样,和栈一样,它的特性是先进先出(FIFO)
SplQueue extends SplDoublyLinkedList implements Iterator , ArrayAccess , Countable { /* 方法 */ __construct ( void ) dequeue ( void ) : mixed enqueue ( mixed $value ) : void setIteratorMode ( int $mode ) : void /* 继承的方法 */ public SplDoublyLinkedList::add ( mixed $index , mixed $newval ) : void public SplDoublyLinkedList::bottom ( void ) : mixed public SplDoublyLinkedList::count ( void ) : int public SplDoublyLinkedList::current ( void ) : mixed public SplDoublyLinkedList::getIteratorMode ( void ) : int public SplDoublyLinkedList::isEmpty ( void ) : bool public SplDoublyLinkedList::key ( void ) : mixed public SplDoublyLinkedList::next ( void ) : void public SplDoublyLinkedList::offsetExists ( mixed $index ) : bool public SplDoublyLinkedList::offsetGet ( mixed $index ) : mixed public SplDoublyLinkedList::offsetSet ( mixed $index , mixed $newval ) : void public SplDoublyLinkedList::offsetUnset ( mixed $index ) : void public SplDoublyLinkedList::pop ( void ) : mixed public SplDoublyLinkedList::prev ( void ) : void public SplDoublyLinkedList::push ( mixed $value ) : void public SplDoublyLinkedList::rewind ( void ) : void public SplDoublyLinkedList::serialize ( void ) : string public SplDoublyLinkedList::setIteratorMode ( int $mode ) : void public SplDoublyLinkedList::shift ( void ) : mixed public SplDoublyLinkedList::top ( void ) : mixed public SplDoublyLinkedList::unserialize ( string $serialized ) : void public SplDoublyLinkedList::unshift ( mixed $value ) : void public SplDoublyLinkedList::valid ( void ) : bool }
4、SplHeap
SplHeap实现了维护堆的功能,堆(Heap)就是为了实现优先队列SplPriorityQueue而设计的一种数据结构,它是通过构造二叉堆(二叉树的一种)实现
abstract SplHeap implements Iterator , Countable { /* 方法 */ public __construct ( void ) abstract protected compare ( mixed $value1 , mixed $value2 ) : int public count ( void ) : int public current ( void ) : mixed public extract ( void ) : mixed public insert ( mixed $value ) : void public isCorrupted ( void ) : bool public isEmpty ( void ) : bool public key ( void ) : mixed public next ( void ) : void public recoverFromCorruption ( void ) : void public rewind ( void ) : void public top ( void ) : mixed public valid ( void ) : bool }
5、SplMaxHeap
SplMaxHeap实现了最大堆的功能,继承自SplHeap
SplMaxHeap extends SplHeap implements Iterator , Countable { /* 方法 */ protected compare ( mixed $value1 , mixed $value2 ) : int /* 继承的方法 */ abstract protected SplHeap::compare ( mixed $value1 , mixed $value2 ) : int public SplHeap::count ( void ) : int public SplHeap::current ( void ) : mixed public SplHeap::extract ( void ) : mixed public SplHeap::insert ( mixed $value ) : void public SplHeap::isCorrupted ( void ) : bool public SplHeap::isEmpty ( void ) : bool public SplHeap::key ( void ) : mixed public SplHeap::next ( void ) : void public SplHeap::recoverFromCorruption ( void ) : void public SplHeap::rewind ( void ) : void public SplHeap::top ( void ) : mixed public SplHeap::valid ( void ) : bool }
6、SplMinHeap
SplMinHeap实现了最小堆的功能,继承自SplHeap:
SplMinHeap extends SplHeap implements Iterator , Countable { /* 方法 */ protected compare ( mixed $value1 , mixed $value2 ) : int /* 继承的方法 */ abstract protected SplHeap::compare ( mixed $value1 , mixed $value2 ) : int public SplHeap::count ( void ) : int public SplHeap::current ( void ) : mixed public SplHeap::extract ( void ) : mixed public SplHeap::insert ( mixed $value ) : void public SplHeap::isCorrupted ( void ) : bool public SplHeap::isEmpty ( void ) : bool public SplHeap::key ( void ) : mixed public SplHeap::next ( void ) : void public SplHeap::recoverFromCorruption ( void ) : void public SplHeap::rewind ( void ) : void public SplHeap::top ( void ) : mixed public SplHeap::valid ( void ) : bool }
7、SplPriorityQueue
百度中的定义:
普通的队列是一种先进先出的数据结构,元素在队列尾追加,而从队列头删除。在优先队列中,元素被赋予优先级。当访问元素时,具有最高优先级的元素最先删除。优先队列具有最高级先出 (first in, largest out)的行为特征。通常采用堆数据结构来实现。
优先队列SplPriorityQueue是基于堆(后文介绍)实现的
SplPriorityQueue implements Iterator , Countable { /* 方法 */ public __construct ( void ) public compare ( mixed $priority1 , mixed $priority2 ) : int public count ( void ) : int public current ( void ) : mixed public extract ( void ) : mixed public getExtractFlags ( void ) : int public insert ( mixed $value , mixed $priority ) : bool public isCorrupted ( void ) : bool public isEmpty ( void ) : bool public key ( void ) : mixed public next ( void ) : void public recoverFromCorruption ( void ) : void public rewind ( void ) : void public setExtractFlags ( int $flags ) : void public top ( void ) : mixed public valid ( void ) : bool }
8、SplFixedArray
SplFixedArray处理巨大数量的固定长度数组是采用,相比与php普通的数组,占用的内存更小。
SplFixedArray implements Iterator , ArrayAccess , Countable { /* 方法 */ public __construct ([ int $size = 0 ] ) public count ( void ) : int public current ( void ) : mixed public static fromArray ( array $array [, bool $save_indexes = TRUE ] ) : SplFixedArray public getSize ( void ) : int public key ( void ) : int public next ( void ) : void public offsetExists ( int $index ) : bool public offsetGet ( int $index ) : mixed public offsetSet ( int $index , mixed $newval ) : void public offsetUnset ( int $index ) : void public rewind ( void ) : void public setSize ( int $size ) : bool public toArray ( void ) : array public valid ( void ) : bool public __wakeup ( void ) : void }
9、 SplObjectStorage
SplObjectStorage用来存储一组对象的,特别是当你需要唯一标识对象的时候
SplObjectStorage implements Countable , Iterator , Serializable , ArrayAccess { /* 方法 */ public addAll ( SplObjectStorage $storage ) : void public attach ( object $object [, mixed $data = NULL ] ) : void public contains ( object $object ) : bool public count ( void ) : int public current ( void ) : object public detach ( object $object ) : void public getHash ( object $object ) : string public getInfo ( void ) : mixed public key ( void ) : int public next ( void ) : void public offsetExists ( object $object ) : bool public offsetGet ( object $object ) : mixed public offsetSet ( object $object [, mixed $data = NULL ] ) : void public offsetUnset ( object $object ) : void public removeAll ( SplObjectStorage $storage ) : void public removeAllExcept ( SplObjectStorage $storage ) : void public rewind ( void ) : void public serialize ( void ) : string public setInfo ( mixed $data ) : void public unserialize ( string $serialized ) : void public valid ( void ) : bool }