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, Vector
s 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. Vector
s do not have "copy-on-write"
semantics.
Vector
s only support integer keys. If a non-integer key is used, an
exception will be thrown.
Vector
s support $m[$k]
style syntax for getting and setting values by
key. Vector
s 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.
Vector
s 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 aVector
containing the values from the specifiedarray
::fromItems(?Traversable<Tv> $iterable): Vector<Tv>
Creates aVector
from the givenTraversable
, or an emptyVector
ifnull
is passed::fromKeysOf<Tk as arraykey>(?KeyedContainer<Tk, mixed> $container): Vector<Tk>
Creates aVector
from the keys of the specified container->__construct(?Traversable<Tv> $iterable = NULL): void
Creates aVector
from the givenTraversable
, or an emptyVector
ifnull
is passed->__toString(): string
Returns thestring
version 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 aVector
that is the concatenation of the values of the currentVector
and 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 aVector
containing the values of the currentVector
that meet a supplied condition->filterWithKey((function(int, Tv): bool) $callback): Vector<Tv>
Returns aVector
containing the values of the currentVector
that 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 currentVector
is empty->items(): Iterable<Tv>
Returns anIterable
view of the currentVector
->keys(): Vector<int>
Returns aVector
containing 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 aVector
containing the results of applying an operation to each value in the currentVector
->mapWithKey<Tu>((function(int, Tv): Tu) $callback): Vector<Tu>
Returns aVector
containing the results of applying an operation to each key/value pair in the currentVector
->pop(): Tv
Remove the last element of the currentVector
and 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 currentVector
in place->set(int $key, Tv $value): Vector<Tv>
Stores a value into the currentVector
with 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 currentVector
associated with each key, overwriting the previous value associated with the key->shuffle(): void
Shuffles the values of the currentVector
randomly in place->skip(int $n): Vector<Tv>
Returns aVector
containing the values after the$n
-th element of the currentVector
->skipWhile((function(Tv): bool) $fn): Vector<Tv>
Returns aVector
containing the values of the currentVector
starting after and including the first value that producesfalse
when passed to the specified callback->slice(int $start, int $len): Vector<Tv>
Returns a subset of the currentVector
starting 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 currentVector
in place->take(int $n): Vector<Tv>
Returns aVector
containing the first$n
values of the currentVector
->takeWhile((function(Tv): bool) $callback): Vector<Tv>
Returns aVector
containing the values of the currentVector
up to but not including the first value that producesfalse
when 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 anarray
whose values are the keys from the currentVector
->toMap(): Map<int, Tv>
Returns an integer-keyedMap
based on the values of the currentVector
->toSet(): Set<Tv>
Returns aSet
based on the values of the currentVector
->toVArray(): varray<Tv>
Returns a varray built from the values from this Vector->toValuesArray(): varray<Tv>
Returns anarray
containing the values from the currentVector
->toVector(): Vector<Tv>
Returns a copy of the currentVector
->values(): Vector<Tv>
Returns aVector
containing the values of the currentVector
->zip<Tu>(Traversable<Tu> $traversable): Vector<Pair<Tv, Tu>>
Returns aVector
where each element is aPair
that combines the element of the currentVector
and the providedTraversable