5 /* An iterator implementation for iterating over a Vector/ImmVector.
7 <<__NativeData("VectorIterator")>>
8 final class VectorIterator
implements HH\Rx\KeyedIterator
{
12 public function __construct(): void
{ }
14 /* Returns the current value that the iterator points to.
17 <<__Native
, __Rx
, __MaybeMutable
>>
18 public function current(): mixed;
20 /* Returns the current key that the iterator points to.
23 <<__Native
, __Rx
, __MaybeMutable
>>
24 public function key(): mixed;
26 /* Returns true if the iterator points to a valid value, returns false
30 <<__Native
, __Rx
, __MaybeMutable
>>
31 public function valid(): bool;
33 /* Advance this iterator forward one position.
35 <<__Native
, __Rx
, __Mutable
>>
36 public function next(): void
;
38 /* Move this iterator back to the first position.
40 <<__Native
, __Rx
, __Mutable
>>
41 public function rewind(): void
;
47 /* An ordered collection where values are keyed using integers 0 thru n-1 in
50 final class Vector
implements \MutableVector
{
52 /* Returns a Vector built from the values produced by the specified Iterable.
53 * @param mixed $iterable
55 <<__Native
, __Rx
, __OnlyRxIfArgs
>>
56 public function __construct(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\Traversable
::class)>> mixed $iterable = null): void
;
58 /* Returns true if the Vector is empty, false otherwise.
61 <<__Rx
, __MaybeMutable
>>
62 public function isEmpty(): bool {
63 return !$this->count();
66 /* Returns the number of values in the Vector.
69 <<__Native
, __Rx
, __MaybeMutable
>>
70 public function count(): int;
72 /* Returns an Iterable that produces the values from this Vector.
75 <<__Rx
, __MutableReturn
, __MaybeMutable
>>
76 public function items(): \LazyIterableView
{
77 return new \
LazyIterableView($this);
80 /* Returns a Vector built from the keys of this Vector.
83 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
84 public function keys(): object;
86 /* Returns a clone of this Vector.
89 <<__Rx
, __MutableReturn
, __MaybeMutable
>>
90 public function values(): this
{
94 /* Returns a lazy iterable view of this Vector.
97 <<__Rx
, __MutableReturn
, __MaybeMutable
>>
98 public function lazy(): \LazyKeyedIterableView
{
99 return new \
LazyKeyedIterableView($this);
102 /* Returns the value at the specified key. If the key is not present, an
103 * exception is thrown.
107 <<__Native
, __Rx
, __MaybeMutable
>>
108 public function at(mixed $key): mixed;
110 /* Returns the value at the specified key. If the key is not present, null is
115 <<__Native
, __Rx
, __MaybeMutable
>>
116 public function get(mixed $key): mixed;
118 /* Stores a value into the Vector with the specified key, overwriting any
119 * previous value that was associated with the key; if the key is outside the
120 * bounds of the Vector, an exception is thrown.
122 * @param mixed $value
125 <<__Native
, __Rx
, __Mutable
, __ReturnsVoidToRx
>>
126 public function set(mixed $key,
127 mixed $value): object;
129 /* Stores each value produced by the specified KeyedIterable into the Vector
130 * using its corresponding key, overwriting any previous value that was
131 * associated with that key; if the key is outside the bounds of the Vector,
132 * an exception is thrown.
133 * @param mixed $iterable
136 <<__Native
, __Rx
, __Mutable
, __OnlyRxIfArgs
, __ReturnsVoidToRx
>>
137 public function setAll(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\KeyedTraversable
::class)>> mixed $iterable): object;
139 /* Removes all values from the Vector.
142 <<__Native
, __Rx
, __Mutable
, __ReturnsVoidToRx
>>
143 public function clear(): object;
145 /* Returns true if the specified key is present in the Vector, returns false
151 "Use Vector::containsKey() for key search or Vector::linearSearch() for value search"
153 public function contains(mixed $key): bool {
154 if (!\
is_int($key)) {
155 throw new \
InvalidArgumentException(
156 "Only integer keys may be used with Vectors"
159 return ($key >= 0) && ($key < $this->count());
162 /* Returns true if the specified key is present in the Vector, returns false
167 <<__Rx
, __MaybeMutable
>>
168 public function containsKey(mixed $key): bool {
169 if (!\
is_int($key)) {
170 throw new \
InvalidArgumentException(
171 "Only integer keys may be used with Vectors"
174 return ($key >= 0) && ($key < $this->count());
177 /* Removes the element with the specified key from this Vector and renumbers
178 * the keys of all subsequent elements.
182 <<__Native
, __Rx
, __Mutable
, __ReturnsVoidToRx
>>
183 public function removeKey(mixed $key): object;
189 public function append(mixed $val): object;
191 /* Adds the specified value to the end of this Vector using the next available
196 <<__Native
, __Rx
, __Mutable
, __ReturnsVoidToRx
>>
197 public function add(mixed $val): object;
199 /* Adds the values produced by the specified Iterable to the end of this
200 * Vector using the next available integer keys.
201 * @param mixed $iterable
204 <<__Native
, __Rx
, __Mutable
, __OnlyRxIfArgs
, __ReturnsVoidToRx
>>
205 public function addAll(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\Traversable
::class)>> mixed $iterable): object;
207 /* Adds the keys of the specified KeyedContainer to the end of this Vector
208 * using the next available integer keys.
209 * @param mixed $container
212 <<__Native
, __Rx
, __Mutable
, __ReturnsVoidToRx
>>
213 public function addAllKeysOf(mixed $container): object;
217 <<__Native
, __Rx
, __Mutable
>>
218 public function pop(): mixed;
221 * @param mixed $value
223 <<__Native
, __Rx
, __Mutable
>>
224 public function resize(mixed $sz,
227 /* Instructs this Vector to grow its capacity to accommodate the given number
228 * of elements. The caller is expected to make the appropriate add/addAll
229 * calls to fill that reserved capacity.
232 <<__Native
, __Rx
, __Mutable
>>
233 public function reserve(mixed $sz): void
;
235 /* Returns an array built from the values from this Vector.
238 <<__Native
, __Rx
, __MaybeMutable
>>
239 public function toArray(): array;
241 <<__Native
, __Rx
, __MaybeMutable
>>
242 public function toVArray(): varray
;
244 <<__Native
, __Rx
, __MaybeMutable
>>
245 public function toDArray(): darray
;
247 /* Returns a copy of this Vector.
250 <<__Rx
, __MutableReturn
, __MaybeMutable
>>
251 public function toVector(): this
{
255 /* Returns a ImmVector built from the values of this Vector.
258 <<__Native
, __Rx
, __MaybeMutable
>>
259 public function toImmVector(): object;
261 /* Returns an immutable version of this collection.
264 <<__Rx
, __MaybeMutable
>>
265 public function immutable(): \HH\ImmVector
{
266 return $this->toImmVector();
269 /* Returns a Map built from the keys and values of this Vector.
272 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
273 public function toMap(): object;
275 /* Returns a ImmMap built from the keys and values of this Vector.
278 <<__Native
, __Rx
, __MaybeMutable
>>
279 public function toImmMap(): object;
281 /* Returns a Set built from the values of this Vector.
284 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
285 public function toSet(): object;
287 /* Returns a ImmSet built from the values of this Vector.
290 <<__Native
, __Rx
, __MaybeMutable
>>
291 public function toImmSet(): object;
293 /* Returns an array built from the keys from this Vector.
296 <<__Rx
, __MaybeMutable
>>
297 public function toKeysArray(): array {
298 $count = $this->count();
299 return $count ?
range(0, $count - 1) : array();
302 /* Returns an array built from the values from this Vector.
305 <<__Rx
, __MaybeMutable
>>
306 public function toValuesArray(): array {
307 return $this->toArray();
310 /* Returns an iterator that points to beginning of this Vector.
313 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
314 public function getIterator(): object;
316 /* Returns a Vector of the values produced by applying the specified callback
317 * on each value from this Vector.
318 * @param mixed $callback
321 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
322 public function map(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
324 /* Returns a Vector of the values produced by applying the specified callback
325 * on each key and value from this Vector.
326 * @param mixed $callback
329 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
330 public function mapWithKey(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
332 /* Returns a Vector of all the values from this Vector for which the specified
333 * callback returns true.
334 * @param mixed $callback
337 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
338 public function filter(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
340 /* Returns a Vector of all the values from this Vector for which the specified
341 * callback returns true.
342 * @param mixed $callback
345 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
346 public function filterWithKey(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
348 /* Returns a KeyedIterable produced by combined the specified Iterables
350 * @param mixed $iterable
353 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
354 public function zip(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\Traversable
::class)>> mixed $iterable): object;
356 /* Returns a Vector containing the first n values of this Vector.
360 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
361 public function take(mixed $n): object;
363 /* Returns a Vector containing the values of this Vector up to but not
364 * including the first value that produces false when passed to the specified
366 * @param mixed $callback
369 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
370 public function takeWhile(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
372 /* Returns a Vector containing all the values except the first n of this
377 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
378 public function skip(mixed $n): object;
380 /* Returns a Vector containing the values of this Vector excluding the first
381 * values that produces true when passed to the specified callback.
385 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
386 public function skipWhile(<<__OnlyRxIfRxFunc
>> mixed $fn): object;
388 /* Returns a Vector containing the specified range of values from this Vector.
389 * The range is specified by two non-negative integers: a starting position
391 * @param mixed $start
395 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
396 public function slice(mixed $start,
399 /* Builds a new Vector by concatenating the elements of this Vector with the
400 * elements of the specified Iterable.
401 * @param mixed $iterable
404 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
405 public function concat(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\Traversable
::class)>> mixed $iterable): object;
407 /* Returns the first value from this Vector, or null if this Vector is empty.
410 <<__Native
, __Rx
, __MaybeMutable
>>
411 public function firstValue(): mixed;
413 /* Returns the first key from this Vector, or null if this Vector is empty.
416 <<__Rx
, __MaybeMutable
>>
417 public function firstKey(): mixed {
418 return $this->count() ?
0 : null;
421 /* Returns the last value from this Vector, or null if this Vector is empty.
424 <<__Native
, __Rx
, __MaybeMutable
>>
425 public function lastValue(): mixed;
427 /* Returns the last key from this Vector, or null if this Vector is empty.
430 <<__Rx
, __MaybeMutable
>>
431 public function lastKey(): mixed {
432 $count = $this->count();
433 return $count ?
($count - 1) : null;
436 /* Reverses the values of the Vector in place.
438 <<__Native
, __Rx
, __Mutable
>>
439 public function reverse(): void
;
441 /* Splices the values of the Vector in place (see the documentation for
442 * array_splice() on php.net for more details.
443 * @param mixed $offset
445 * @param mixed $replacement
447 <<__Native
, __Rx
, __Mutable
>>
448 public function splice(mixed $offset,
450 mixed $replacement = null): void
;
452 /* Returns index of the specified value if it is present, -1 otherwise.
453 * @param mixed $search_value
456 <<__Native
, __Rx
, __MaybeMutable
>>
457 public function linearSearch(mixed $search_value): int;
459 /* Shuffles the values of the Vector randomly in place.
461 <<__Native
, __Rx
, __Mutable
>>
462 public function shuffle(): void
;
466 <<__Rx
, __MaybeMutable
>>
467 public function __toString(): string { return "Vector"; }
469 /* @param mixed $name
472 public function __get(mixed $name): mixed {
473 throw new \
InvalidOperationException(
474 "Cannot access a property on a collection"
478 /* @param mixed $name
479 * @param mixed $value
482 public function __set(mixed $name,
483 mixed $value): mixed {
484 throw new \
InvalidOperationException(
485 "Cannot access a property on a collection"
489 /* @param mixed $name
492 public function __isset(mixed $name): bool { return false; }
494 /* @param mixed $name
497 public function __unset(mixed $name): mixed {
498 throw new \
InvalidOperationException(
499 "Cannot access a property on a collection"
503 /* Returns a Vector built from the values produced by the specified Iterable.
504 * @param mixed $iterable
507 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
508 public static function fromItems(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\Traversable
::class)>> mixed $iterable): object;
510 /* Returns a Vector built from the keys of the specified container.
511 * @param mixed $container
514 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
515 public static function fromKeysOf(mixed $container): object;
517 /* Returns a Vector built from the values from the specified array.
522 public static function fromArray(mixed $arr): object;
525 /* An immutable ordered collection where values are keyed using integers 0
528 final class ImmVector
implements \ConstVector
{
530 /* Returns a ImmVector built from the values produced by the specified
532 * @param mixed $iterable
534 <<__Native
, __Rx
, __OnlyRxIfArgs
>>
535 public function __construct(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\Traversable
::class)>> mixed $iterable = null): void
;
537 /* Returns an ImmVector built from the values produced by the specified
539 * @param mixed $iterable
542 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MaybeMutable
>>
543 public static function fromItems(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\Traversable
::class)>> mixed $iterable): object;
545 /* Returns a ImmVector built from the keys of the specified container.
546 * @param mixed $container
549 <<__Native
, __Rx
, __MaybeMutable
>>
550 public static function fromKeysOf(mixed $container): object;
552 /* Returns true if the ImmVector is empty, false otherwise.
555 <<__Rx
, __MaybeMutable
>>
556 public function isEmpty(): bool {
557 return !$this->count();
560 /* Returns the number of values in the ImmVector.
563 <<__Native
, __Rx
, __MaybeMutable
>>
564 public function count(): int;
566 /* Returns an Iterable that produces the values from this ImmVector.
569 <<__Rx
, __MutableReturn
, __MaybeMutable
>>
570 public function items(): \LazyIterableView
{
571 return new \
LazyIterableView($this);
574 /* Returns true if the specified key is present in the ImmVector, returns
579 <<__Rx
, __MaybeMutable
>>
580 public function containsKey(mixed $key): bool {
581 if (!\
is_int($key)) {
582 throw new \
InvalidArgumentException(
583 "Only integer keys may be used with Vectors"
586 return ($key >= 0) && ($key < $this->count());
589 /* Returns the value at the specified key. If the key is not present, an
590 * exception is thrown.
594 <<__Native
, __Rx
, __MaybeMutable
>>
595 public function at(mixed $key): mixed;
597 /* Returns the value at the specified key. If the key is not present, null is
602 <<__Native
, __Rx
, __MaybeMutable
>>
603 public function get(mixed $key): mixed;
605 /* Returns an iterator that points to beginning of this ImmVector.
608 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
609 public function getIterator(): object;
611 /* Returns a Vector of the values produced by applying the specified callback
612 * on each value from this ImmVector.
613 * @param mixed $callback
616 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
617 public function map(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
619 /* Returns a Vector of the values produced by applying the specified callback
620 * on each key and value from this ImmVector.
621 * @param mixed $callback
624 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
625 public function mapWithKey(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
627 /* Returns a Vector of all the values from this ImmVector for which the
628 * specified callback returns true.
629 * @param mixed $callback
632 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
633 public function filter(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
635 /* Returns a Vector of all the values from this ImmVector for which the
636 * specified callback returns true.
637 * @param mixed $callback
640 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
641 public function filterWithKey(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
643 /* Returns a KeyedIterable produced by combined the specified Iterables
645 * @param mixed $iterable
648 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
649 public function zip(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\Traversable
::class)>> mixed $iterable): object;
651 /* Returns a ImmVector containing the first n values of this ImmVector.
655 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
656 public function take(mixed $n): object;
658 /* Returns a ImmVector containing the values of this ImmVector up to but not
659 * including the first value that produces false when passed to the specified
661 * @param mixed $callback
664 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
665 public function takeWhile(<<__OnlyRxIfRxFunc
>> mixed $callback): object;
667 /* Returns a ImmVector containing all values except the first n of this
672 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
673 public function skip(mixed $n): object;
675 /* Returns a ImmVector containing the values of this ImmVector excluding the
676 * first values that produces true when passed to the specified callback.
680 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
681 public function skipWhile(<<__OnlyRxIfRxFunc
>> mixed $fn): object;
683 /* Returns an ImmVector containing the specified range of values from this
684 * ImmVector. The range is specified by two non-negative integers: a starting
685 * position and a length.
686 * @param mixed $start
690 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
691 public function slice(mixed $start,
694 /* Builds a new ImmVector by concatenating the elements of this ImmVector with
695 * the elements of the specified Iterable.
696 * @param mixed $iterable
699 <<__Native
, __Rx
, __OnlyRxIfArgs
, __MutableReturn
, __MaybeMutable
>>
700 public function concat(<<__MaybeMutable
, __OnlyRxIfImpl(HH\Rx\Traversable
::class)>> mixed $iterable): object;
702 /* Returns the first value from this ImmVector, or null if this ImmVector is
706 <<__Native
, __Rx
, __MaybeMutable
>>
707 public function firstValue(): mixed;
709 /* Returns the first key from this ImmVector, or null if this ImmVector is
713 <<__Rx
, __MaybeMutable
>>
714 public function firstKey(): mixed {
715 return $this->count() ?
0 : null;
718 /* Returns the last value from this ImmVector, or null if this ImmVector is
722 <<__Native
, __Rx
, __MaybeMutable
>>
723 public function lastValue(): mixed;
725 /* Returns the last key from this ImmVector, or null if this ImmVector is
729 <<__Rx
, __MaybeMutable
>>
730 public function lastKey(): mixed {
731 $count = $this->count();
732 return $count ?
($count - 1) : null;
735 /* Returns an Iterable that produces the keys from this ImmVector.
738 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
739 public function keys(): object;
743 <<__Rx
, __MaybeMutable
>>
744 public function __toString(): string { return "ImmVector"; }
746 /* @param mixed $name
749 public function __get(mixed $name): mixed {
750 throw new \
InvalidOperationException(
751 "Cannot access a property on a collection"
755 /* @param mixed $name
756 * @param mixed $value
759 public function __set(mixed $name,
760 mixed $value): mixed {
761 throw new \
InvalidOperationException(
762 "Cannot access a property on a collection"
766 /* @param mixed $name
769 public function __isset(mixed $name): bool { return false; }
771 /* @param mixed $name
774 public function __unset(mixed $name): mixed {
775 throw new \
InvalidOperationException(
776 "Cannot access a property on a collection"
780 /* Returns a Vector built from the values of this ImmVector.
783 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
784 public function toVector(): object;
786 /* Returns an immutable version of this collection.
789 <<__Rx
, __MaybeMutable
>>
790 public function toImmVector(): this
{
794 /* Returns a Map built from the keys and values of this ImmVector.
797 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
798 public function toMap(): object;
800 /* Returns a ImmMap built from the keys and values of this ImmVector.
803 <<__Native
, __Rx
, __MaybeMutable
>>
804 public function toImmMap(): object;
806 /* Returns a Set built from the values of this ImmVector.
809 <<__Native
, __Rx
, __MutableReturn
, __MaybeMutable
>>
810 public function toSet(): object;
812 /* Returns a ImmSet built from the values of this ImmVector.
815 <<__Native
, __Rx
, __MaybeMutable
>>
816 public function toImmSet(): object;
818 /* Returns an immutable version of this collection.
821 <<__Rx
, __MaybeMutable
>>
822 public function immutable(): this
{
826 /* Returns a clone of this ImmVector.
829 <<__Rx
, __MutableReturn
, __MaybeMutable
>>
830 public function values(): this
{
834 /* Returns a lazy iterable view of this ImmVector.
837 <<__Rx
, __MutableReturn
, __MaybeMutable
>>
838 public function lazy(): \LazyKeyedIterableView
{
839 return new \
LazyKeyedIterableView($this);
842 /* Returns an array built from the values from this ImmVector.
845 <<__Native
, __Rx
, __MaybeMutable
>>
846 public function toArray(): array;
848 <<__Native
, __Rx
, __MaybeMutable
>>
849 public function toVArray(): varray
;
851 <<__Native
, __Rx
, __MaybeMutable
>>
852 public function toDArray(): darray
;
854 /* Returns an array built from the keys from this ImmVector.
857 <<__Rx
, __MaybeMutable
>>
858 public function toKeysArray(): array {
859 $count = $this->count();
860 return $count ?
range(0, $count - 1) : array();
863 /* Returns an array built from the values from this ImmVector.
866 <<__Rx
, __MaybeMutable
>>
867 public function toValuesArray(): array {
868 return $this->toArray();
871 /* Returns index of the specified value if it is present, -1 otherwise.
872 * @param mixed $search_value
875 <<__Native
, __Rx
, __MaybeMutable
>>
876 public function linearSearch(mixed $search_value): int;