PHP SPL Data Structure notes summary

Source: Internet
Author: User
Tags spl
The main data structures used by PHP SPL (standard PHP Library) are: Doubly linked list (Spldoublylinkedlis), Stack (splstack), queue (Splqueue), Heap (Splheap), Dagen ( SPLMAXHEAP), small Gan (splminheap), Priority queue (Splpriorityqueue), fixed array (splfixedarray), Object Store (splstorageobject).

Spldoublylinkedlist

Data structure: (C code reference PHP7.0.0)

typedef struct _spl_ptr_llist_element {struct _spl_ptr_llist_element *prev;    struct _spl_ptr_llist_element *next;      int RC;    Number of citations void *data;      Data type} spl_ptr_llist_element;typedef struct _spl_ptr_llist {spl_ptr_llist_element *head;    Spl_ptr_llist_element *tail;    Spl_ptr_llist_dtor_func dtor;    Delete Element Reference-1 Spl_ptr_llist_ctor_func ctor;                        Create an element reference +1 int count;    Number of elements} spl_ptr_llist;struct _spl_dllist_object {zend_object std;    Spl_ptr_llist *llist;    int traverse_position;    Spl_ptr_llist_element *traverse_pointer;    Zval *retval;    int flags;    Zend_function *fptr_offset_get;    Zend_function *fptr_offset_set;    Zend_function *fptr_offset_has;    Zend_function *fptr_offset_del;    Zend_function *fptr_count; Zend_class_entry *ce_geT_iterator; HashTable *debug_info;};

Doubly linked list spldoublylinkedlist implements Iterator, arrayaccess, countable {/* method */public __construct (void) public void add (Mixed $index, mixed $newval) public mixed Bottom (void) public int count (void) public mixed current (void) public I NT Getiteratormode (void) public bool IsEmpty (void) public mixed key (void) public void next (void) public bool OFFSE Texists (mixed $index) public mixed offsetget (mixed $index) public void Offsetset (mixed $index, mixed $newval) publi c void Offsetunset (mixed $index) public mixed pops (void) public void prev (void) public void push (mixed $value) publ IC void Rewind (void) public string serialize (void) public void Setiteratormode (int. $mode) public mixed shift (void )      //Delete first element public mixed top (void) public void unserialize (string $serialized) public void unshift (mixed $value )   //Insert value into the first element, the original first element does not delete public bool valid (void)}

It is important to note that:

Add is a function added by the 5.5+ version, and the others are 5.3+

As can be seen from the data structure, although many functions contain a direct index element, the Outofrangeexception exception is thrown if it is not in scope, and the actual implementation time complexity is O (n).

Detailed functions can be found in the PHP official manual

The above describes the PHP SPL data structure Note Summary, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.