HH\Vector
Vector is a stack-like collection
HHVM provides a native implementation for this class. The PHP class definition below is not actually used at run time; it is simply provided for the typechecker and for developer reference.
Like all objects in PHP, Vectors have reference-like semantics. When a
caller passes a Vector to a callee, the callee can modify the Vector and
the caller will see the changes. Vectors do not have "copy-on-write"
semantics.
Vectors only support integer keys. If a non-integer key is used, an
exception will be thrown.
Vectors support $m[$k] style syntax for getting and setting values by
key. Vectors also support isset($m[$k]) and empty($m[$k]) syntax, and
they provide similar semantics as arrays. Elements can be added to a
Vector using $m[] = .. syntax.
Vectors do not support iterating while new elements are being added or
elements are being removed. When a new element is added or removed, all
iterators that point to the Vector shall be considered invalid.
Guides
Interface Synopsis
namespace HH;
final class Vector implements \MutableVector<Tv> {...}
Public Methods
::fromArray(darray<arraykey, Tv> $arr): Vector<Tv>
Returns aVectorcontaining the values from the specifiedarray::fromItems(?Traversable<Tv> $iterable): Vector<Tv>
Creates aVectorfrom the givenTraversable, or an emptyVectorifnullis passed::fromKeysOf<Tk as arraykey>(?KeyedContainer<Tk, mixed> $container): Vector<Tk>
Creates aVectorfrom the keys of the specified container->__construct(?Traversable<Tv> $iterable = NULL): void
Creates aVectorfrom the givenTraversable, or an emptyVectorifnullis passed->__toString(): string
Returns thestringversion of the currentVector, which is"Vector"->add(Tv $value): Vector<Tv>
Appends a value to the end of the currentVector, assigning it the next available integer key->addAll(?Traversable<Tv> $iterable): Vector<Tv>
For every element in the providedTraversable, append a value into thisVector, assigning the next available integer key for each->addAllKeysOf(?KeyedContainer<Tv, mixed> $container): Vector<Tv>
Adds the keys of the specified container to the currentVector->append(mixed $value): this->at(int $key): Tv
Returns the value at the specified key in the currentVector->clear(): Vector<Tv>
Removes all the elements from the currentVector->concat<Tu super Tv>(Traversable<Tu> $traversable): Vector<Tu>
Returns aVectorthat is the concatenation of the values of the currentVectorand the values of the providedTraversable->contains(mixed $key): bool
Returns true if the specified key is present in the Vector, returns false otherwise->containsKey(mixed $key): bool
Determines if the specified key is in the currentVector->count(): int
Returns the number of elements in the currentVector->filter((function(Tv): bool) $callback): Vector<Tv>
Returns aVectorcontaining the values of the currentVectorthat meet a supplied condition->filterWithKey((function(int, Tv): bool) $callback): Vector<Tv>
Returns aVectorcontaining the values of the currentVectorthat meet a supplied condition applied to its keys and values->firstKey(): ?int
Returns the first key in the currentVector->firstValue(): ?Tv
Returns the first value in the currentVector->get(int $key): ?Tv
Returns the value at the specified key in the currentVector->getIterator(): KeyedIterator<int, Tv>
Returns an iterator that points to beginning of the currentVector->immutable(): ImmVector<Tv>
Returns an immutable copy (ImmVector) of the currentVector->isEmpty(): bool
Checks if the currentVectoris empty->items(): Iterable<Tv>
Returns anIterableview of the currentVector->keys(): Vector<int>
Returns aVectorcontaining the keys of the currentVector->lastKey(): ?int
Returns the last key in the currentVector->lastValue(): ?Tv
Returns the last value in the currentVector->lazy(): KeyedIterable<int, Tv>
Returns a lazy, access-elements-only-when-needed view of the currentVector->linearSearch(mixed $search_value): int
Returns the index of the first element that matches the search value->map<Tu>((function(Tv): Tu) $callback): Vector<Tu>
Returns aVectorcontaining the results of applying an operation to each value in the currentVector->mapWithKey<Tu>((function(int, Tv): Tu) $callback): Vector<Tu>
Returns aVectorcontaining the results of applying an operation to each key/value pair in the currentVector->pop(): Tv
Remove the last element of the currentVectorand return it->removeKey(int $key): Vector<Tv>
Removes the key/value pair with the specified key from the currentVector->reserve(int $sz): void
Reserves enough memory to accommodate a given number of elements->resize(int $size, Tv $value): void
Resize the currentVector->reverse(): void
Reverse the elements of the currentVectorin place->set(int $key, Tv $value): Vector<Tv>
Stores a value into the currentVectorwith the specified key, overwriting the previous value associated with the key->setAll(?KeyedTraversable<int, Tv> $iterable): Vector<Tv>
For every element in the providedTraversable, stores a value into the currentVectorassociated with each key, overwriting the previous value associated with the key->shuffle(): void
Shuffles the values of the currentVectorrandomly in place->skip(int $n): Vector<Tv>
Returns aVectorcontaining the values after the$n-th element of the currentVector->skipWhile((function(Tv): bool) $fn): Vector<Tv>
Returns aVectorcontaining the values of the currentVectorstarting after and including the first value that producesfalsewhen passed to the specified callback->slice(int $start, int $len): Vector<Tv>
Returns a subset of the currentVectorstarting from a given key up to, but not including, the element at the provided length from the starting key->splice(int $offset, ?int $len = NULL): void
Splice the currentVectorin place->take(int $n): Vector<Tv>
Returns aVectorcontaining the first$nvalues of the currentVector->takeWhile((function(Tv): bool) $callback): Vector<Tv>
Returns aVectorcontaining the values of the currentVectorup to but not including the first value that producesfalsewhen passed to the specified callback->toDArray(): darray<int, Tv>->toImmMap(): ImmMap<int, Tv>
Returns an immutable, integer-keyed map (ImmMap) based on the values of the currentVector->toImmSet(): ImmSet<Tv>
Returns an immutable set (ImmSet) based on the values of the currentVector->toImmVector(): ImmVector<Tv>
Returns an immutable copy (ImmVector) of the currentVector->toKeysArray(): varray<int>
Returns anarraywhose values are the keys from the currentVector->toMap(): Map<int, Tv>
Returns an integer-keyedMapbased on the values of the currentVector->toSet(): Set<Tv>
Returns aSetbased on the values of the currentVector->toVArray(): varray<Tv>
Returns a varray built from the values from this Vector->toValuesArray(): varray<Tv>
Returns anarraycontaining the values from the currentVector->toVector(): Vector<Tv>
Returns a copy of the currentVector->values(): Vector<Tv>
Returns aVectorcontaining the values of the currentVector->zip<Tu>(Traversable<Tu> $traversable): Vector<Pair<Tv, Tu>>
Returns aVectorwhere each element is aPairthat combines the element of the currentVectorand the providedTraversable