PHP7 above to install and use this data structure extension, the installation is relatively simple:
Collection Interface : Contains basic interface for all the common functions of data structures in this library. It guarantees that all structures is traversable, countable, and can be converted to JSON using json_encode ().
Ds\collection implements Traversable, countable, jsonserializable {/* method */abstract public void Clear (void) Abstract P ublic ds\collection copy (void) abstract public bool IsEmpty (void) abstract public array toArray (void)}
hashable Interface:which allows objects to be used as keys.
ds\hashable {/* method */abstract public bool Equals (object $obj) abstract public mixed hash (void)}
Sequence Interface:a Sequence is equivalent to a one-dimensional numeric key array with the exception of a few characteristics:
Use cases:
Wherever you would use an array as a list (not concerned with keys).
A more efficient alternative to spldoublylinkedlist and Splfixedarray.
Values would always be indexed as [0, 1, 2, ..., size-1].
Only allowed to access values by index in the range [0, size-1].
vector Class: Vectors are a series of values in a continuous buffer that automatically grows and shrinks. It is the most efficient sequential structure in which the index of the value is mapped directly to the index in the buffer, and the growth factor is not bound to a specific multiplier or exponent. It has the following advantages and disadvantages:
Ds\vector::allocate-allocates enough memory a required capacity.::apply-updates all values by applying a to
value.::capacity-returns the capacity.::clear-removes all values.::__construct-creates a instance.:: Contains-determines the vector contains given Values.::-returns a shallow of the vector.::-returns the o F values in the collection.::filter-creates a vectors using a callable to determine which values to.:: Find-attemp TS to find a value '
Supports array Syntax (square brackets).
Uses less overall memory than a array for the same number of values.
Automatically frees allocated memory when it size drops low enough.
Capacity does not has to be a power of 2.
Get (), set (), push (), pop () is all O (1).
But shift (), unshift (), Insert () and remove () is all O (n).
-
Deque Class : The abbreviation for "double-ended queue", also used in Ds\queue, has head, tail two pointers. the pointers can "wrap around" the end of the buffer, which a Voids the need to move and other values around to make. This makes shift and unshift very fast-something a ds\vector can ' t compete with. It has the following advantages and disadvantages:
-
Support s array syntax (square brackets).
-
uses less overall memory than a array for the same number of Valu Es.
-
automatically frees allocated memory when it size drops low enough.
-
get (), set (), push (), pop (), shift (), and unshift () is all O (1).
-
But capacity must be a power of 2. Insert () and remove () is O (n).
Map Class: A contiguous set of key-value pairs, almost the same as an array. The key can be of any type, but must be unique. If you use the same key to add to the map, the value is replaced. It has the following advantages and disadvantages:
Keys and values can is any type, including objects.
Supports array Syntax (square brackets).
Insertion Order is preserved.
Performance and memory efficiency is very similar to an array.
Automatically frees allocated memory when it size drops low enough.
Can ' t is converted to a array when objects is used as keys.
pair Class: A pair is used by Ds\map to Pair keys with values.
Ds\pair implements Jsonserializable {/* method */public __construct ([Mixed $key [, mixed $value])}
Set Class: A sequence of unique values. This implementation uses the same hash table as Ds\map, where values be used as keys and the mapped value is ignored. It has the following advantages and disadvantages:
Values can is any type, including objects.
Supports array Syntax (square brackets).
Insertion Order is preserved.
Automatically frees allocated memory when it size drops low enough.
Add (), Remove () and contains () is all O (1).
but doesn ' t support push (), pop (), Insert (), shift (), or unshift (). get () is O (n) If there was deleted values in the buffer before the accessed index, O (1) otherwise.
-
Stack Class : "Last in, first Out "collection, which allows access and iteration only at the top of the structure.
ds\stack implements Ds\collection {/* method */public void Allocate (int $capacity) public int capacity (void) public void clear (void) public ds\stack copy (void) public bool I Sempty (void) public mixed peek (void) public mixed pops (void) public void push ([mixed $...values]) public array ToA Rray (void)}
-
queue Class : "first in, first Out" collection allows access and iteration only at the front of the fabric.
ds\queue implements Ds\collection {/* Constants */const int Min_capacity = 8;/* method */public void Allocate (int $capacity) public int capacity (void) public void clear (void) Publ IC ds\queue copy (void) public bool IsEmpty (void) public mixed peek (void) public mixed pop (void) public void push ( [Mixed $...values]) Public array toArray (void)}
-
Priorityqueue class : The priority queue is very similar to the queue, but the value is pushed into the queue with the specified priority. The highest priority value is always in front of the queue and remains in the first in, first out order with priority elements. recursion on a priorityqueue is destructive, equivalent to a continuous popup operation until the queue is empty. Implemented using a max heap.
ds\priorityqueue implements Ds\collection {/* Constants */const int min_capacity = 8;/* method */public void Allocate (int $capacity) public int capacity (void) public void clear (void) public Ds\priorit Yqueue copy (void) public bool IsEmpty (void) public mixed peek (void) public mixed pops (void) public void push (Mixe d $value, int $priority) public array toArray (void)}