PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / ramsey / collection / src / DoubleEndedQueueInterface.php

DoubleEndedQueueInterface.php in Defender Security – Malware Scanner, Login Security & Firewall 3.0.1, at vendor/ramsey/collection/src/DoubleEndedQueueInterface.php

317 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the ramsey/collection library
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * @copyright Copyright (c) Ben Ramsey <[email protected]>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12
13 declare(strict_types=1);
14
15 namespace Ramsey\Collection;
16
17 use Ramsey\Collection\Exception\NoSuchElementException;
18
19 /**
20 * A linear collection that supports element insertion and removal at both ends.
21 *
22 * Most `DoubleEndedQueueInterface` implementations place no fixed limits on the
23 * number of elements they may contain, but this interface supports
24 * capacity-restricted double-ended queues as well as those with no fixed size
25 * limit.
26 *
27 * This interface defines methods to access the elements at both ends of the
28 * double-ended queue. Methods are provided to insert, remove, and examine the
29 * element. Each of these methods exists in two forms: one throws an exception
30 * if the operation fails, the other returns a special value (either `null` or
31 * `false`, depending on the operation). The latter form of the insert operation
32 * is designed specifically for use with capacity-restricted implementations; in
33 * most implementations, insert operations cannot fail.
34 *
35 * The twelve methods described above are summarized in the following table:
36 *
37 * <table>
38 * <caption>Summary of DoubleEndedQueueInterface methods</caption>
39 * <thead>
40 * <tr>
41 * <th></th>
42 * <th colspan=2>First Element (Head)</th>
43 * <th colspan=2>Last Element (Tail)</th>
44 * </tr>
45 * <tr>
46 * <td></td>
47 * <td><em>Throws exception</em></td>
48 * <td><em>Special value</em></td>
49 * <td><em>Throws exception</em></td>
50 * <td><em>Special value</em></td>
51 * </tr>
52 * </thead>
53 * <tbody>
54 * <tr>
55 * <th>Insert</th>
56 * <td><code>addFirst()</code></td>
57 * <td><code>offerFirst()</code></td>
58 * <td><code>addLast()</code></td>
59 * <td><code>offerLast()</code></td>
60 * </tr>
61 * <tr>
62 * <th>Remove</th>
63 * <td><code>removeFirst()</code></td>
64 * <td><code>pollFirst()</code></td>
65 * <td><code>removeLast()</code></td>
66 * <td><code>pollLast()</code></td>
67 * </tr>
68 * <tr>
69 * <th>Examine</th>
70 * <td><code>firstElement()</code></td>
71 * <td><code>peekFirst()</code></td>
72 * <td><code>lastElement()</code></td>
73 * <td><code>peekLast()</code></td>
74 * </tr>
75 * </tbody>
76 * </table>
77 *
78 * This interface extends the `QueueInterface`. When a double-ended queue is
79 * used as a queue, FIFO (first-in-first-out) behavior results. Elements are
80 * added at the end of the double-ended queue and removed from the beginning.
81 * The methods inherited from the `QueueInterface` are precisely equivalent to
82 * `DoubleEndedQueueInterface` methods as indicated in the following table:
83 *
84 * <table>
85 * <caption>Comparison of QueueInterface and DoubleEndedQueueInterface methods</caption>
86 * <thead>
87 * <tr>
88 * <th>QueueInterface Method</th>
89 * <th>DoubleEndedQueueInterface Method</th>
90 * </tr>
91 * </thead>
92 * <tbody>
93 * <tr>
94 * <td><code>add()</code></td>
95 * <td><code>addLast()</code></td>
96 * </tr>
97 * <tr>
98 * <td><code>offer()</code></td>
99 * <td><code>offerLast()</code></td>
100 * </tr>
101 * <tr>
102 * <td><code>remove()</code></td>
103 * <td><code>removeFirst()</code></td>
104 * </tr>
105 * <tr>
106 * <td><code>poll()</code></td>
107 * <td><code>pollFirst()</code></td>
108 * </tr>
109 * <tr>
110 * <td><code>element()</code></td>
111 * <td><code>firstElement()</code></td>
112 * </tr>
113 * <tr>
114 * <td><code>peek()</code></td>
115 * <td><code>peekFirst()</code></td>
116 * </tr>
117 * </tbody>
118 * </table>
119 *
120 * Double-ended queues can also be used as LIFO (last-in-first-out) stacks. When
121 * a double-ended queue is used as a stack, elements are pushed and popped from
122 * the beginning of the double-ended queue. Stack concepts are precisely
123 * equivalent to `DoubleEndedQueueInterface` methods as indicated in the table
124 * below:
125 *
126 * <table>
127 * <caption>Comparison of stack concepts and DoubleEndedQueueInterface methods</caption>
128 * <thead>
129 * <tr>
130 * <th>Stack concept</th>
131 * <th>DoubleEndedQueueInterface Method</th>
132 * </tr>
133 * </thead>
134 * <tbody>
135 * <tr>
136 * <td><em>push</em></td>
137 * <td><code>addFirst()</code></td>
138 * </tr>
139 * <tr>
140 * <td><em>pop</em></td>
141 * <td><code>removeFirst()</code></td>
142 * </tr>
143 * <tr>
144 * <td><em>peek</em></td>
145 * <td><code>peekFirst()</code></td>
146 * </tr>
147 * </tbody>
148 * </table>
149 *
150 * Note that the `peek()` method works equally well when a double-ended queue is
151 * used as a queue or a stack; in either case, elements are drawn from the
152 * beginning of the double-ended queue.
153 *
154 * While `DoubleEndedQueueInterface` implementations are not strictly required
155 * to prohibit the insertion of `null` elements, they are strongly encouraged to
156 * do so. Users of any `DoubleEndedQueueInterface` implementations that do allow
157 * `null` elements are strongly encouraged *not* to take advantage of the
158 * ability to insert nulls. This is so because `null` is used as a special
159 * return value by various methods to indicated that the double-ended queue is
160 * empty.
161 *
162 * @template T
163 * @template-extends QueueInterface<T>
164 */
165 interface DoubleEndedQueueInterface extends QueueInterface
166 {
167 /**
168 * Inserts the specified element at the front of this queue if it is
169 * possible to do so immediately without violating capacity restrictions.
170 *
171 * When using a capacity-restricted double-ended queue, it is generally
172 * preferable to use the `offerFirst()` method.
173 *
174 * @param T $element The element to add to the front of this queue.
175 *
176 * @return bool `true` if this queue changed as a result of the call.
177 *
178 * @throws \RuntimeException if a queue refuses to add a particular element
179 * for any reason other than that it already contains the element.
180 * Implementations should use a more-specific exception that extends
181 * `\RuntimeException`.
182 */
183 // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
184 public function addFirst($element): bool;
185
186 /**
187 * Inserts the specified element at the end of this queue if it is possible
188 * to do so immediately without violating capacity restrictions.
189 *
190 * When using a capacity-restricted double-ended queue, it is generally
191 * preferable to use the `offerLast()` method.
192 *
193 * This method is equivalent to `add()`.
194 *
195 * @param T $element The element to add to the end of this queue.
196 *
197 * @return bool `true` if this queue changed as a result of the call.
198 *
199 * @throws \RuntimeException if a queue refuses to add a particular element
200 * for any reason other than that it already contains the element.
201 * Implementations should use a more-specific exception that extends
202 * `\RuntimeException`.
203 */
204 // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
205 public function addLast($element): bool;
206
207 /**
208 * Inserts the specified element at the front of this queue if it is
209 * possible to do so immediately without violating capacity restrictions.
210 *
211 * When using a capacity-restricted queue, this method is generally
212 * preferable to `addFirst()`, which can fail to insert an element only by
213 * throwing an exception.
214 *
215 * @param T $element The element to add to the front of this queue.
216 *
217 * @return bool `true` if the element was added to this queue, else `false`.
218 */
219 // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
220 public function offerFirst($element): bool;
221
222 /**
223 * Inserts the specified element at the end of this queue if it is possible
224 * to do so immediately without violating capacity restrictions.
225 *
226 * When using a capacity-restricted queue, this method is generally
227 * preferable to `addLast()` which can fail to insert an element only by
228 * throwing an exception.
229 *
230 * @param T $element The element to add to the end of this queue.
231 *
232 * @return bool `true` if the element was added to this queue, else `false`.
233 */
234 // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
235 public function offerLast($element): bool;
236
237 /**
238 * Retrieves and removes the head of this queue.
239 *
240 * This method differs from `pollFirst()` only in that it throws an
241 * exception if this queue is empty.
242 *
243 * @return T the first element in this queue.
244 *
245 * @throws NoSuchElementException if this queue is empty.
246 */
247 public function removeFirst();
248
249 /**
250 * Retrieves and removes the tail of this queue.
251 *
252 * This method differs from `pollLast()` only in that it throws an exception
253 * if this queue is empty.
254 *
255 * @return T the last element in this queue.
256 *
257 * @throws NoSuchElementException if this queue is empty.
258 */
259 public function removeLast();
260
261 /**
262 * Retrieves and removes the head of this queue, or returns `null` if this
263 * queue is empty.
264 *
265 * @return T|null the head of this queue, or `null` if this queue is empty.
266 */
267 public function pollFirst();
268
269 /**
270 * Retrieves and removes the tail of this queue, or returns `null` if this
271 * queue is empty.
272 *
273 * @return T|null the tail of this queue, or `null` if this queue is empty.
274 */
275 public function pollLast();
276
277 /**
278 * Retrieves, but does not remove, the head of this queue.
279 *
280 * This method differs from `peekFirst()` only in that it throws an
281 * exception if this queue is empty.
282 *
283 * @return T the head of this queue.
284 *
285 * @throws NoSuchElementException if this queue is empty.
286 */
287 public function firstElement();
288
289 /**
290 * Retrieves, but does not remove, the tail of this queue.
291 *
292 * This method differs from `peekLast()` only in that it throws an exception
293 * if this queue is empty.
294 *
295 * @return T the tail of this queue.
296 *
297 * @throws NoSuchElementException if this queue is empty.
298 */
299 public function lastElement();
300
301 /**
302 * Retrieves, but does not remove, the head of this queue, or returns `null`
303 * if this queue is empty.
304 *
305 * @return T|null the head of this queue, or `null` if this queue is empty.
306 */
307 public function peekFirst();
308
309 /**
310 * Retrieves, but does not remove, the tail of this queue, or returns `null`
311 * if this queue is empty.
312 *
313 * @return T|null the tail of this queue, or `null` if this queue is empty.
314 */
315 public function peekLast();
316 }
317