* @copyright © 2019 PHP Documentation Group
* @license CC-BY 3.0, https://www.php.net/manual/en/cc.license.php
*/
namespace Ds;
use ArrayAccess;
use Countable;
use IteratorAggregate;
use JsonSerializable;
use OutOfBoundsException;
use OutOfRangeException;
use Traversable;
use UnderflowException;
/**
* Collection is the base interface which covers functionality common to all
* the data structures in this library. It guarantees that all structures
* are traversable, countable, and can be converted to json using
* json_encode().
* @package Ds
*
* @template-covariant TKey
* @template-covariant TValue
* @extends IteratorAggregate Note: Casting to an array is not supported yet. Note: Capacity will stay the same if this value is
* less than or equal to the current capacity. Note: You can insert at the index equal to the number of values. Note: The values of the current instance won't be
* affected.
* Note: The current instance is not affected.
* Caution: Returning non-integer values from the comparison
* function, such as float, will result in an internal cast to integer
* of the callback's return value. So values such as 0.99 and 0.1 will
* both be cast to an integer value of 0, which will compare such
* values as equal.
* Caution: Returning non-integer values from the comparison
* function, such as float, will result in an internal cast to integer
* of the callback's return value. So values such as 0.99 and 0.1 will
* both be cast to an integer value of 0, which will compare such
* values as equal. Note: Arrays and objects are considered equal to zero when
* calculating the sum. Note: Multiple values will be added in the same order that they
* are passed.
*
*
*
* Use cases:
*
*
* @package Ds
* @template TValue
* @extends Collectioncallback ( mixed $value ) : mixed
* @link https://www.php.net/manual/en/ds-sequence.apply.php
*/
public function apply(callable $callback): void;
/**
* Returns the current capacity.
* @return int The current capacity.
* @link https://www.php.net/manual/en/ds-sequence.capacity.php
*/
public function capacity(): int;
/**
* Determines if the sequence contains all values.
* @param TValue ...$values Values to check.
* @return bool FALSE if any of the provided values are not in the
* sequence, TRUE otherwise.
* @link https://www.php.net/manual/en/ds-sequence.contains.php
*/
public function contains(...$values): bool;
/**
* Creates a new sequence using a callable to determine which values
* to include.
* @param null|callable(TValue): bool $callback Optional callable which returns TRUE if the
* value should be included, FALSE otherwise. If a callback is not
* provided, only values which are TRUE (see converting to boolean) will
* be included.
* callback ( mixed $value ) : bool
* @return Sequencecallback ( mixed $value ) : mixed
* @return Sequence
* callback ( mixed $carry , mixed $value ) : mixed
* $carry The return value of the previous callback, or initial if it's
* the first iteration.
* $value The value of the current iteration.
* callback ( mixed $a, mixed $b ) : int
callback ( mixed $a, mixed $b ) : int
* Strengths
*
*
*
Note: Capacity will stay the same if this value is less than or * equal to the current capacity.
* @link https://www.php.net/manual/en/ds-vector.allocate.php */ public function allocate(int $capacity): void {} /** * Updates all values by applying a callback function to each value in * the vector. * @param callable(TValue): TValue $callback *callback ( mixed $value ) : mixed
* A callable to apply to each value in the vector. The callback should
* return what the value should be replaced by.
* @link https://www.php.net/manual/en/ds-vector.apply.php
*/
public function apply(callable $callback): void {}
/**
* Returns the current capacity.
* @return int The current capacity.
* @link https://www.php.net/manual/en/ds-vector.capacity.php
*/
public function capacity(): int {}
/**
* Removes all values from the vector.
* @link https://www.php.net/manual/en/ds-vector.clear.php
*/
public function clear(): void {}
/**
* Determines if the vector contains all values.
* @param TValue ...$values Values to check.
* @return bool FALSE if any of the provided values are not in the
* vector, TRUE otherwise.
* @link https://www.php.net/manual/en/ds-vector.contains.php
*/
public function contains(...$values): bool {}
/**
*Returns a shallow copy of the vector.
* @return Vectorcallback ( mixed $value ) : bool
* @return VectorNote: Values will be compared by value and by type.
* @link https://www.php.net/manual/en/ds-vector.find.php */ public function find($value) {} /** * Returns the first value in the vector. * @return TValue * @throws UnderflowException if empty. * @link https://www.php.net/manual/en/ds-vector.first.php */ public function first() {} /** * Returns the value at a given index. * @param int $index The index to access, starting at 0. * @return TValue * @link https://www.php.net/manual/en/ds-vector.get.php */ public function get(int $index) {} public function getIterator(): Traversable {} /** * Inserts values into the sequence at a given index. * * @param int $index The index at which to insert. 0 <= index <= count * Note:callback ( mixed $carry , mixed $value ) : mixed
callback ( mixed $a, mixed $b ) : int
* Caution: Returning non-integer values from the comparison function,
* such as float, will result in an
* internal cast to integer of the callback's return value. So values
* such as 0.99 and 0.1 will both be cast to an integer value of 0,
* which will compare such values as equal.
*/
public function sort(?callable $comparator = null): void {}
/**
* Returns a sorted copy, using an optional comparator function.
* @link https://www.php.net/manual/en/ds-vector.sorted.php
* @param callable(TValue, TValue): int|null $comparator The comparison function must return an integer less than, equal to, or
* greater than zero if the first argument is considered to be respectively less than, equal to, or greater
* than the second. Note that before PHP 7.0.0 this integer had to be in the range from -2147483648 to
* 2147483647.callback ( mixed $a, mixed $b ) : int
* Caution: Returning non-integer values from the comparison function, such as float, will result in an
* internal cast to integer of the callback's return value. So values such as 0.99 and 0.1 will both be cast to
* an integer value of 0, which will compare such values as equal.
* @return Vector* The return value is cast to an integer. *
* @since 5.1 */ public function count(): int {} /** * Returns whether the collection is empty. * @link https://www.php.net/manual/en/ds-vector.isempty.php * @return bool */ public function isEmpty(): bool {} /** * Converts the collection to an array. *Note: Casting to an array is not supported yet.
* @link https://www.php.net/manual/en/ds-vector.toarray.php * @return array* The return value is cast to an integer. *
* @since 5.1 */ public function count(): int {} /** * Removes all values from the deque. * @link https://www.php.net/manual/en/ds-deque.clear.php */ public function clear(): void {} /** * Returns a shallow copy of the deque. * @link https://www.php.net/manual/en/ds-deque.copy.php * @return DequeNote: Casting to an array is not supported yet.
* @link https://www.php.net/manual/en/ds-deque.toarray.php * @return arrayNote: Capacity will stay the same if this value is * less than or equal to the current capacity.
*Note: Capacity will always be rounded up to the nearest power of 2.
* @link https://www.php.net/manual/en/ds-deque.allocate.php */ public function allocate(int $capacity): void {} /** * Updates all values by applying a callback function to each value in * the deque. * @param callable(TValue): TValue $callback A callable to apply to each value in the * deque. The callback should return what the value should be * replaced by.
* callback ( mixed $value ) : mixed
*
* callback ( mixed $value ) : bool
*
Note: You can insert at the index equal to the number of values.
* @param TValue ...$values The value or values to insert. * @throws OutOfRangeException if the index is not valid. * @link https://www.php.net/manual/en/ds-deque.insert.php */ public function insert(int $index, ...$values): void {} /** * Joins all values together as a string using an optional separator * between each value. * @param string $glue An optional string to separate each value. * @return string All values of the deque joined together as a * string. * @link https://www.php.net/manual/en/ds-deque.join.php */ public function join(string $glue = ''): string {} /** * Returns the last value in the deque. * @return TValue The last value in the deque. * @throws UnderflowException if empty. * @link https://www.php.net/manual/en/ds-deque.last.php */ public function last() {} /** * Returns the result of applying a callback function to each value in * the deque. * * @template TNewValue * @param callable(TValue): TNewValue $callback A callable to apply to each value in the * deque. * The callable should return what the new value will be in the new * deque. *callback ( mixed $value ) : mixed
*
* @return DequeNote: The values of the current instance won't be * affected.
* @link https://www.php.net/manual/en/ds-deque.map.php */ public function map(callable $callback): Deque {} /** * Returns the result of adding all given values to the deque. * @template TValue2 * @param iterablecallback ( mixed $carry , mixed $value ) : mixed
* $carry The return value of the previous callback, or initial if it's
* the first iteration.* $value The value of the current iteration. *
* @param TCarry $initial The initial value of the carry value. Can be NULL. * @return TCarry The return value of the final callback. * @link https://www.php.net/manual/en/ds-deque.reduce.php */ public function reduce(callable $callback, $initial = null) {} /** * Removes and returns a value by index. * @param int $index The index of the value to remove. * @return TValue The value that was removed. * @link https://www.php.net/manual/en/ds-deque.remove.php */ public function remove(int $index) {} /** * Reverses the deque in-place. * @link https://www.php.net/manual/en/ds-deque.reverse.php */ public function reverse(): void {} /** * Returns a reversed copy of the deque. * @return DequeNote: The current instance is not affected.
*/ public function reversed(): Deque {} /** * Rotates the deque by a given number of rotations, which is * equivalent to successively calling * $deque->push($deque->shift()) if the number of rotations is * positive, or $deque->unshift($deque->pop()) if negative. * @param int $rotations The number of times the deque should be * rotated. * @link https://www.php.net/manual/en/ds-deque.rotate.php */ public function rotate(int $rotations): void {} /** * Updates a value at a given index. * @param int $index The index of the value to update. * @param TValue $value The new value. * @throws OutOfRangeException if the index is not valid. * @link https://www.php.net/manual/en/ds-deque.set.php */ public function set(int $index, $value): void {} /** * Removes and returns the first value. * @return TValue * @throws UnderflowException if empty. * @link https://www.php.net/manual/en/ds-deque.shift.php */ public function shift() {} /** * Creates a sub-deque of a given range. * @param int $index The index at which the sub-deque starts. * If positive, the deque will start at that index in the deque. * If negative, the deque will start that far from the end. * @param int|null $length If a length is given and is positive, the * resulting deque will have up to that many values in it. If the * length results in an overflow, only values up to the end of the * deque will be included. If a length is given and is negative, * the deque will stop that many values from the end. If a length * is not provided, the resulting deque will contain all values * between the index and the end of the deque. * @return Dequecallback ( mixed $a, mixed $b ) : int
* Caution: Returning non-integer values from the comparison * function, such as float, will result in an internal cast to integer * of the callback's return value. So values such as 0.99 and 0.1 will * both be cast to an integer value of 0, which will compare such * values as equal.
* @link https://www.php.net/manual/en/ds-deque.sort.php */ public function sort(?callable $comparator = null): void {} /** * Returns a sorted copy, using an optional comparator function. * @param callable(TValue, TValue): int|null $comparator The comparison function must return * an integer less than, equal to, or greater than zero if the first * argument is considered to be respectively less than, equal to, or * greater than the second. Note that before PHP 7.0.0 this integer had * to be in the range from -2147483648 to 2147483647. *callback ( mixed $a, mixed $b ) : int
* Caution: Returning non-integer values from the comparison * function, such as float, will result in an internal cast to integer * of the callback's return value. So values such as 0.99 and 0.1 will * both be cast to an integer value of 0, which will compare such * values as equal.
* @return DequeNote: Arrays and objects are considered equal to zero when * calculating the sum.
* @return float|int The sum of all the values in the deque as * either a float or int depending on the values in the deque. */ public function sum(): float|int {} /** * Adds values to the front of the deque, moving all the current * values forward to make room for the new values. * @param TValue ...$values The values to add to the front of the deque. *Note: Multiple values will be added in the same order that they * are passed.
*/ public function unshift(...$values): void {} /** * Specify data which should be serialized to JSON * @link https://php.net/manual/en/ds-vector.jsonserialize.php * @return mixed data which can be serialized by json_encode, * which is a value of any type other than a resource. * @since 5.4 */ public function jsonSerialize() {} /** * @param int $offset */ public function offsetExists(mixed $offset): bool {} /** * @param int $offset * * @return TValue */ public function offsetGet(mixed $offset) {} /** * @param int $offset * @param TValue $value */ public function offsetSet(mixed $offset, mixed $value) {} /** * @param int $offset */ public function offsetUnset(mixed $offset): void {} } /** * @template TKey * @template TValue * @implements CollectionNote: Capacity will stay the same if this value is less than or equal to the current capacity.
* Capacity will always be rounded up to the nearest power of 2. * * @link https://www.php.net/manual/en/ds-map.allocate.php */ public function allocate(int $capacity) {} /** * Updates all values by applying a callback function to each value in the map. * * @param callable(TKey, TValue): TValue $callback A callable to apply to each value in the map. The callback should return what * the value should be replaced by. * * @link https://www.php.net/manual/en/ds-map.apply.php */ public function apply(callable $callback) {} /** * Returns the current capacity. * * @return int * * @link https://www.php.net/manual/en/ds-map.capacity.php */ public function capacity(): int {} /** * Count elements of an object * @link https://php.net/manual/en/countable.count.php * @return int The custom count as an integer. * *
* The return value is cast to an integer.
* @since 5.1
*/
public function count(): int {}
/**
* Removes all values from the collection.
* @link https://www.php.net/manual/en/ds-collection.clear.php
*/
public function clear(): void {}
/**
* Returns a shallow copy of the collection.
* @link https://www.php.net/manual/en/ds-collection.copy.php
* @return Map
* Note: Keys of type object are supported. If an object implements Ds\Hashable, equality will be
* determined by the object's equals function. If an object does not implement Ds\Hashable, objects must be references to the same instance to be considered equal.
*
* Note: You can also use array syntax to access values by key, eg. $map["key"].
*
* Caution: Be careful when using array syntax. Scalar keys will be coerced to integers by the engine. For
* example, $map["1"] will attempt to access int(1), while $map->get("1") will correctly look up the string key.
* Note: Values from the current instance will be kept. Note: Casting to an array is not supported yet. Caution: Maps where non-scalar keys are can't be converted to an
* array.
* Caution: An array will treat all numeric keys as integers, eg.
* "1" and 1 as keys in the map will only result in 1 being included in
* the array.
* Caution: Returning non-integer values from the comparison function, such
* as float, will result in an internal cast to integer of the
* callback's return value. So values such as 0.99 and 0.1 will both be
* cast to an integer value of 0, which will compare such values as
* equal. Caution: Returning non-integer values from the comparison function, such
* as float, will result in an internal cast to integer of the
* callback's return value. So values such as 0.99 and 0.1 will both be
* cast to an integer value of 0, which will compare such values as
* equal. Note: The current instance is not affected. Note: Values of the current instance will be overwritten by those
* provided where keys are equal. Note: Casting to an array is not supported yet. Note: Values of type object are supported. If an object implements
* Ds\Hashable, equality will be determined by the object's equals
* function. If an object does not implement Ds\Hashable, objects must
* be references to the same instance to be considered equal.
*
* Caution: All comparisons are strict (type and value).
*
* @param TValue ...$values Values to add to the set.
*
* @link https://php.net/manual/en/ds-set.add.php
*/
public function add(...$values) {}
/**
* Allocates enough memory for a required capacity.
*
* @param int $capacity The number of values for which capacity should
* be allocated.
*
* Note: Capacity will stay the same if this value is less than or
* equal to the current capacity.
*
* Capacity will always be rounded up to the nearest power of 2.
*
* @link https://php.net/manual/en/ds-set.allocate.php
*/
public function allocate(int $capacity) {}
/**
* Determines if the set contains all values.
*
* Values of type object are supported. If an object implements
* Ds\Hashable, equality will be determined by the object's equals
* function. If an object does not implement Ds\Hashable, objects must
* be references to the same instance to be considered equal.
*
* Caution: All comparisons are strict (type and value).
*
* @param TValue ...$values Values to check.
*
* @return bool
*
* @link https://php.net/manual/en/ds-set.contains.php
*/
public function contains(...$values): bool {}
/**
* Returns the current capacity.
* @link https://www.php.net/manual/en/ds-set.capacity.php
*
* @return int
*/
public function capacity(): int {}
/**
* Removes all values from the set.
* @link https://www.php.net/manual/en/ds-set.clear.php
*/
public function clear(): void {}
/**
* Count elements of an object
* @link https://php.net/manual/en/ds-set.count.php
* @return int The custom count as an integer.
*
* The return value is cast to an integer.
* @since 5.1
*/
public function count(): int {}
/**
* Returns a shallow copy of the set.
* @link https://www.php.net/manual/en/ds-set.copy.php
* @return Set Note: The values of the current instance won't be affected. Note: The current instance won't be affected. Note: The current instance is not affected. Caution: Returning non-integer values from the comparison
* function, such as float, will result in an
* internal cast to integer of the callback's return value. So values
* such as 0.99 and 0.1 will both be cast to an integer value of 0,
* which will compare such values as equal. Note: Arrays and objects are considered equal to zero when
* calculating the sum. Note: Casting to an array is not supported yet. Note: Capacity will stay the same if this value is less than or
* equal to the current capacity.
* The return value is cast to an integer.
* @since 5.1
*/
public function count(): int {}
/**
* Returns a shallow copy of the collection.
* @link https://www.php.net/manual/en/ds-stack.copy.php
* @return Stack Note: Casting to an array is not supported yet. Note: Capacity will stay the same if this value is less than or
* equal to the current capacity.
* The return value is cast to an integer.
* @since 5.1
*/
public function count(): int {}
/**
* Returns a shallow copy of the collection.
* @link https://www.php.net/manual/en/ds-queue.copy.php
* @return Queue Note: Casting to an array is not supported yet.
* The return value is cast to an integer.
* @since 5.1
*/
public function count(): int {}
/**
* Allocates enough memory for a required capacity
* @link https://www.php.net/manual/en/ds-priorityqueue.allocate.php
*
* @param int $capacity
*/
public function allocate(int $capacity): void {}
/**
* Returns the current capacity
* @link https://www.php.net/manual/en/ds-priorityqueue.capacity.php
*
* @return int
*/
public function capacity(): int {}
/**
* Removes all values from the collection.
* @link https://www.php.net/manual/en/ds-collection.clear.php
*/
public function clear(): void {}
/**
* Returns a shallow copy of the collection.
* @link https://www.php.net/manual/en/ds-collection.copy.php
* @return PriorityQueue Note: Casting to an array is not supported yet.callback ( mixed $a, mixed $b ) : int
* callback ( mixed $a, mixed $b ) : int
* callback ( mixed $key , mixed $value ) : mixed
* @return Mapcallback ( mixed $carry , mixed $key , mixed $value ) : mixed
* carry The return value of the previous callback, or initial if
* it's the first iteration.
* key The key of the current iteration.
* value The value of the current iteration.
*
* @param TCarry $initial The initial value of the carry value. Can be
* NULL.
*
* @return TCarry
* @link https://www.php.net/manual/en/ds-map.reduce.php
*/
public function reduce(callable $callback, $initial) {}
/**
* Removes and returns a value by key, or return an optional default
* value if the key could not be found.
*
* @template TDefault
* @param TKey $key The key to remove.
* @param TDefault $default The optional default value, returned if the key
* could not be found.
*
* Note: Keys of type object are supported. If an object implements
* Ds\Hashable, equality will be determined
* by the object's equals function. If an object does not implement
* Ds\Hashable, objects must be references to the same instance to be
* considered equal.
*
* Note: You can also use array syntax to access values by key, eg.
* $map["key"].
*
* Caution: Be careful when using array syntax. Scalar keys will be
* coerced to integers by the engine. For example, $map["1"] will
* attempt to access int(1), while $map->get("1") will correctly look up
* the string key.
*
* @return TValue|TDefault The value that was removed, or the default value if
* provided and the key could not be found in the map.
*
* @throws OutOfBoundsException if the key could not be found and a
* default value was not provided.
*
* @link https://www.php.net/manual/en/ds-map.remove.php
*/
public function remove($key, $default = null) {}
/**
* Reverses the map in-place.
*
* @link https://www.php.net/manual/en/ds-map.reverse.php
*/
public function reverse() {}
/**
* Returns a reversed copy of the map.
*
* @return Mapcallback ( mixed $a, mixed $b ) : int
*
* Caution: Returning non-integer values from the comparison function,
* such as float, will result in an internal cast to integer of the
* callback's return value. So values such as 0.99 and 0.1 will both be
* cast to an integer value of 0, which will compare such values as
* equal.
*
* @link https://www.php.net/manual/en/ds-map.sort.php
*/
public function sort(?callable $comparator = null) {}
/**
* Returns a copy, sorted by value using an optional comparator function.
*
* @param callable(TValue, TValue): int|null $comparator The comparison function must return
* an integer less than, equal to, or greater than zero if the first
* argument is considered to be respectively less than, equal to, or
* greater than the second. Note that before PHP 7.0.0 this integer had
* to be in the range from -2147483648 to 2147483647.
*
* callback ( mixed $a, mixed $b ) : int
*
* Caution: Returning non-integer values from the comparison function,
* such as float, will result in an internal cast to integer of the
* callback's return value. So values such as 0.99 and 0.1 will both be
* cast to an integer value of 0, which will compare such values as
* equal.
*
* @return Mapcallback ( mixed $value ) : mixed
* @return Setcallback ( mixed $carry , mixed $value ) : mixed
* $carry The return value of the previous callback, or initial if
* it's the first iteration.
* $value The value of the current iteration.
*
* @param TCarry $initial The initial value of the carry value. Can be
* NULL.
*
* @return TCarry The return value of the final callback.
*/
public function reduce(callable $callback, $initial = null) {}
/**
* Removes all given values from the set, ignoring any that are not in
* the set.
*
* @link https://www.php.net/manual/en/ds-set.remove.php
*
* @param TValue ...$values The values to remove.
*/
public function remove(...$values) {}
/**
* Reverses the set in-place.
*
* @link https://www.php.net/manual/en/ds-set.reverse.php
*/
public function reverse() {}
/**
* Returns a reversed copy of the set.
*
* @link https://www.php.net/manual/en/ds-set.reversed.php
*
* callback ( mixed $a, mixed $b ) : int
* callback ( mixed $a, mixed $b ) : int
*
*