|
| 1 | +<?php |
| 2 | + |
| 3 | +/** @generate-class-entries */ |
| 4 | + |
| 5 | +namespace Collections; |
| 6 | + |
| 7 | +/** |
| 8 | + * A double-ended queue (Typically abbreviated as Deque, pronounced "deck", like "cheque") |
| 9 | + * represented internally as a circular buffer. |
| 10 | + * |
| 11 | + * This has much lower memory usage than SplDoublyLinkedList or its subclasses (SplStack, SplStack), |
| 12 | + * and operations are significantly faster than SplDoublyLinkedList. |
| 13 | + * |
| 14 | + * See https://en.wikipedia.org/wiki/Double-ended_queue |
| 15 | + * |
| 16 | + * This supports amortized constant time pushing and popping onto the front or back of the Deque. |
| 17 | + * |
| 18 | + * Naming is based on https://www.php.net/spldoublylinkedlist |
| 19 | + * and on array_push/pop/unshift/shift and array_key_first. |
| 20 | + */ |
| 21 | +final class Deque implements \IteratorAggregate, \Countable, \JsonSerializable, \ArrayAccess |
| 22 | +{ |
| 23 | + /** Construct the Deque from the values of the Traversable/array, ignoring keys */ |
| 24 | + public function __construct(iterable $iterator = []) {} |
| 25 | + /** |
| 26 | + * Returns an iterator that accounts for calls to shift/unshift tracking the position of the start of the Deque. |
| 27 | + * Calls to shift/unshift will do the following: |
| 28 | + * - Increase/Decrease the value returned by the iterator's key() |
| 29 | + * by the number of elements added/removed to/from the start of the Deque. |
| 30 | + * (`$deque[$iteratorKey] === $iteratorValue` at the time the key and value are returned). |
| 31 | + * - Repeated calls to shift will cause valid() to return false if the iterator's |
| 32 | + * position ends up before the start of the Deque at the time iteration resumes. |
| 33 | + * - They will not cause the remaining values to be iterated over more than once or skipped. |
| 34 | + */ |
| 35 | + public function getIterator(): \InternalIterator {} |
| 36 | + /** Returns the number of elements in the Deque. */ |
| 37 | + public function count(): int {} |
| 38 | + /** Returns true if there are 0 elements in the Deque. */ |
| 39 | + public function isEmpty(): bool {} |
| 40 | + /** Removes all elements from the Deque. */ |
| 41 | + public function clear(): void {} |
| 42 | + |
| 43 | + /** @implementation-alias Collections\Deque::toArray */ |
| 44 | + public function __serialize(): array {} |
| 45 | + public function __unserialize(array $data): void {} |
| 46 | + /** Construct the Deque from the values of the array, ignoring keys */ |
| 47 | + public static function __set_state(array $array): Deque {} |
| 48 | + |
| 49 | + /** Appends value(s) to the end of the Deque, like array_push. */ |
| 50 | + public function push(mixed ...$values): void {} |
| 51 | + /** Prepends value(s) to the start of the Deque, like array_unshift. */ |
| 52 | + public function unshift(mixed ...$values): void {} |
| 53 | + /** |
| 54 | + * Pops a value from the end of the Deque. |
| 55 | + * @throws \UnderflowException if the Deque is empty |
| 56 | + */ |
| 57 | + public function pop(): mixed {} |
| 58 | + /** |
| 59 | + * Shifts a value from the start of the Deque. |
| 60 | + * @throws \UnderflowException if the Deque is empty |
| 61 | + */ |
| 62 | + public function shift(): mixed {} |
| 63 | + |
| 64 | + /** |
| 65 | + * Peeks at the value at the start of the Deque. |
| 66 | + * @throws \UnderflowException if the Deque is empty |
| 67 | + */ |
| 68 | + public function first(): mixed {} |
| 69 | + /** |
| 70 | + * Peeks at the value at the end of the Deque. |
| 71 | + * @throws \UnderflowException if the Deque is empty |
| 72 | + */ |
| 73 | + public function last(): mixed {} |
| 74 | + |
| 75 | + /** |
| 76 | + * Returns a list of the elements from the start to the end. |
| 77 | + */ |
| 78 | + public function toArray(): array {} |
| 79 | + |
| 80 | + /** |
| 81 | + * Insert 0 or more values at the given offset of the Deque. |
| 82 | + * @throws \OutOfBoundsException if the value of $offset is not within the bounds of this Deque. |
| 83 | + */ |
| 84 | + public function insert(int $offset, mixed ...$values): void {} |
| 85 | + // Must be mixed for compatibility with ArrayAccess |
| 86 | + /** |
| 87 | + * Returns the value at offset (int)$offset (relative to the start of the Deque) |
| 88 | + * @throws \OutOfBoundsException if the value of (int)$offset is not within the bounds of this Deque. |
| 89 | + */ |
| 90 | + public function offsetGet(mixed $offset): mixed {} |
| 91 | + /** |
| 92 | + * Returns true if `0 <= (int)$offset && (int)$offset < $this->count() |
| 93 | + * AND the value at that offset is non-null. |
| 94 | + */ |
| 95 | + public function offsetExists(mixed $offset): bool {} |
| 96 | + /** |
| 97 | + * Sets the value at offset $offset (relative to the start of the Deque) to $value |
| 98 | + * @throws \OutOfBoundsException if the value of (int)$offset is not within the bounds of this Deque. |
| 99 | + */ |
| 100 | + public function offsetSet(mixed $offset, mixed $value): void {} |
| 101 | + /** |
| 102 | + * Removes the value at (int)$offset from the deque. |
| 103 | + * @throws \OutOfBoundsException if the value of (int)$offset is not within the bounds of this Deque. |
| 104 | + */ |
| 105 | + public function offsetUnset(mixed $offset): void {} |
| 106 | + |
| 107 | + /** |
| 108 | + * This is JSON serialized as a JSON array with elements from the start to the end. |
| 109 | + * @implementation-alias Collections\Deque::toArray |
| 110 | + */ |
| 111 | + public function jsonSerialize(): array {} |
| 112 | +} |
0 commit comments