HH\Set
Set is an ordered set-style 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, Sets have reference-like semantics. When a caller
passes a Set to a callee, the callee can modify the Set and the caller
will see the changes. Sets do not have "copy-on-write" semantics.
Sets preserve insertion order of the elements. When iterating over a
Set, the elements appear in the order they were inserted. Also, Sets do
not automagically convert integer-like strings (ex. "123") into integers.
Sets only support int values and string values. If a value of a
different type is used, an exception will be thrown.
In general, Sets do not support $c[$k] style syntax. Adding an element
using $c[] = .. syntax is supported.
Set do not support iteration while elements are being added or removed.
When an element is added or removed, all iterators that point to the Set
shall be considered invalid.
Guides
Examples
More documentation and examples are in the
[Set and ImmSet](</hack/arrays-and-collections/collections#set-and-immset>)
guide.
Interface Synopsis
namespace HH;
final class Set implements \MutableSet<Tv> {...}
Public Methods
::fromArray(darray<arraykey, Tv> $arr): Set<Tv>
Returns aSetcontaining the values from the specifiedarray::fromArrays(...$argv): Set<Tv>
Returns aSetcontaining all the values from the specifiedarray(s)::fromItems(?Traversable<Tv> $iterable): Set<Tv>
Creates aSetfrom the givenTraversable, or an emptySetifnullis passed::fromKeysOf<Tk as arraykey>(?KeyedContainer<Tk, mixed> $container): Set<Tk>
Creates aSetfrom the keys of the specified container->__construct(?Traversable<Tv> $iterable = NULL): void
Creates aSetfrom the givenTraversable, or an emptySetifnullis passed->__toString(): string
Returns thestringversion of the currentSet, which is"Set"->add(Tv $val): Set<Tv>
Add the value to the currentSet->addAll(?Traversable<Tv> $iterable): Set<Tv>
For every element in the providedTraversable, add the value into the currentSet->addAllKeysOf(?KeyedContainer<Tv, mixed> $container): Set<Tv>
Adds the keys of the specified container to the currentSetas new values->clear(): Set<Tv>
Remove all the elements from the currentSet->concat<Tu super Tv>(Traversable<Tu> $traversable): Vector<Tu>
Returns aVectorthat is the concatenation of the values of the currentSetand the values of the providedTraversable->contains(arraykey $val): bool
Determines if the specified value is in the currentSet->count(): int
Provides the number of elements in the currentSet->difference(mixed $iterable)->filter((function(Tv): bool) $callback): Set<Tv>
Returns aSetcontaining the values of the currentSetthat meet a supplied condition applied to each value->filterWithKey((function(arraykey, Tv): bool) $callback): Set<Tv>
Returns aSetcontaining the values of the currentSetthat meet a supplied condition applied to its "keys" and values->firstKey(): ?arraykey
Returns the first "key" in the currentSet->firstValue(): ?Tv
Returns the first value in the currentSet->getIterator(): KeyedIterator<arraykey, Tv>
Returns an iterator that points to beginning of the currentSet->immutable(): ImmSet<Tv>
Returns an immutable (ImmSet), deep copy of the currentSet->isEmpty(): bool
Checks if the currentSetis empty->items(): Iterable<Tv>
Returns anIterableview of the currentSet->keys(): Vector<arraykey>
Returns aVectorcontaining the values of the currentSet->lastKey(): ?arraykey
Returns the last "key" in the currentSet->lastValue(): ?Tv
Returns the last value in the currentSet->lazy(): KeyedIterable<arraykey, Tv>
Returns a lazy, access elements only when needed view of the currentSet->map<Tu as arraykey>((function(Tv): Tu) $callback): Set<Tu>
Returns aSetcontaining the values after an operation has been applied to each value in the currentSet->mapWithKey<Tu as arraykey>((function(arraykey, Tv): Tu) $callback): Set<Tu>
Returns aSetcontaining the values after an operation has been applied to each "key" and value in the currentSet->remove(Tv $val): Set<Tv>
Removes the specified value from the currentSet->removeAll(Traversable<Tv> $iterable): Set<Tv>
Removes the values in the currentSetthat are also in theTraversable->reserve(int $sz): void
Reserves enough memory to accommodate a given number of elements->retain((function(Tv): bool) $callback): Set<Tv>
Alters the currentSetso that it only contains the values that meet a supplied condition on each value->retainWithKey((function(arraykey, Tv): bool) $callback): Set<Tv>
Alters the currentSetso that it only contains the values that meet a supplied condition on its "keys" and values->skip(int $n): Set<Tv>
Returns aSetcontaining the values after then-th element of the currentSet->skipWhile((function(Tv): bool) $fn): Set<Tv>
Returns aSetcontaining the values of the currentSetstarting after and including the first value that producestruewhen passed to the specified callback->slice(int $start, int $len): Set<Tv>
Returns a subset of the currentSetstarting from a given key up to, but not including, the element at the provided length from the starting key->take(int $n): Set<Tv>
Returns aSetcontaining the firstnvalues of the currentSet->takeWhile((function(Tv): bool) $callback): Set<Tv>
Returns aSetcontaining the values of the currentSetup to but not including the first value that producesfalsewhen passed to the specified callback->toDArray(): darray<Tv, Tv>
Returns a darray built from the values from this Set, darray[val1 => val1, val2 => val2, ...]->toImmMap(): ImmMap<arraykey, Tv>
Returns an immutable map (ImmMap) based on the values of the currentSet->toImmSet(): ImmSet<Tv>
Returns an immutable (ImmSet), deep copy of the currentSet->toImmVector(): ImmVector<Tv>
Returns an immutable vector (ImmVector) with the values of the currentSet->toKeysArray(): varray<Tv>
Returns anarraycontaining the values from the currentSet->toMap(): Map<arraykey, Tv>
Returns aMapbased on the values of the currentSet->toSet(): Set<Tv>
Returns a deep copy of the currentSet->toVArray(): varray<Tv>->toValuesArray(): varray<Tv>
Returns anarraycontaining the values from the currentSet->toVector(): Vector<Tv>
Returns aVectorof the currentSetvalues->values(): Vector<Tv>
Returns aVectorcontaining the values of the currentSet->zip<Tu>(Traversable<Tu> $traversable): Set<nothing>
Throws an exception unless the currentSetor theTraversableis empty