Collection is the base class which covers functionality common to all the data structures in this library.
- $container: array - contains the collection values
- count - Returns the number of values in the map
- clear - Removes all values
- isEmpty - Returns whether the queue is empty
A Queue is a “first in, first out” or “FIFO” collection that only allows access to the value at the front of the queue and iterates in that order, destructively.
- peek - Returns the value at the front of the queue
- pop - Removes and returns the value at the front of the queue
- push($value) - Pushes a value into the queue
A Sequence describes the behaviour of values arranged in a single, linear dimension. Some languages refer to this as a "List". It’s similar to an array that uses incremental integer keys, with the exception of a few characteristics:
- get($index) - Returns the value for a given index
- insert($index, $value) - Inserts values at a given index, eg :
$sequence->insert(0, "e"); // [e]
$sequence->insert(1, "f"); // [e, f]
$sequence->insert(2, "g"); // [e, f, g]
$sequence->insert(0, "a"); // [a, e, f, g]
Hint: you should use array_splice
:
$original = array( 'a', 'b', 'c', 'd', 'e' );
$inserted = array( 'x' ); // not necessarily an array, see manual quote
array_splice( $original, 3, 0, $inserted ); // splice in at position 3
// $original is now a b c x d e