HH\Set (original) (raw)
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, Set
s 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. Set
s do not have "copy-on-write" semantics.
Set
s preserve insertion order of the elements. When iterating over aSet
, the elements appear in the order they were inserted. Also, Set
s do not automagically convert integer-like strings (ex. "123") into integers.
Set
s 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
Returns aSet
containing the values from the specifiedarray
- ::fromArrays(...$argv): Set
Returns aSet
containing all the values from the specifiedarray
(s) - ::fromItems(?Traversable $iterable): Set
Creates aSet
from the given Traversable, or an emptySet
ifnull
is passed - ::fromKeysOf(?KeyedContainer<Tk, mixed> $container): Set
Creates aSet
from the keys of the specified container - ->__construct(?Traversable $iterable = NULL): void
Creates aSet
from the given Traversable, or an emptySet
ifnull
is passed - ->__toString(): string
Returns thestring
version of the currentSet
, which is"Set"
- ->add(Tv $val): Set
Add the value to the currentSet
- ->addAll(?Traversable $iterable): Set
For every element in the provided Traversable, add the value into the currentSet
- ->addAllKeysOf(?KeyedContainer<Tv, mixed> $container): Set
Adds the keys of the specified container to the currentSet
as new values - ->clear(): Set
Remove all the elements from the currentSet
- ->concat(Traversable $traversable): Vector
Returns a Vector that is the concatenation of the values of the currentSet
and the values of the provided Traversable - ->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
Returns aSet
containing the values of the currentSet
that meet a supplied condition applied to each value - ->filterWithKey((function(arraykey, Tv): bool) $callback): Set
Returns aSet
containing the values of the currentSet
that 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
Returns an immutable (ImmSet), deep copy of the currentSet
- ->isEmpty(): bool
Checks if the currentSet
is empty - ->items(): Iterable
Returns an Iterable view of the currentSet
- ->keys(): Vector
Returns a Vector containing 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((function(Tv): Tu) $callback): Set
Returns aSet
containing the values after an operation has been applied to each value in the currentSet
- ->mapWithKey((function(arraykey, Tv): Tu) $callback): Set
Returns aSet
containing the values after an operation has been applied to each "key" and value in the currentSet
- ->remove(Tv $val): Set
Removes the specified value from the currentSet
- ->removeAll(Traversable $iterable): Set
Removes the values in the currentSet
that are also in the Traversable - ->reserve(int $sz): void
Reserves enough memory to accommodate a given number of elements - ->retain((function(Tv): bool) $callback): Set
Alters the currentSet
so that it only contains the values that meet a supplied condition on each value - ->retainWithKey((function(arraykey, Tv): bool) $callback): Set
Alters the currentSet
so that it only contains the values that meet a supplied condition on its "keys" and values - ->skip(int $n): Set
Returns aSet
containing the values after then
-th element of the currentSet
- ->skipWhile((function(Tv): bool) $fn): Set
Returns aSet
containing the values of the currentSet
starting after and including the first value that producestrue
when passed to the specified callback - ->slice(int start,intstart, int start,intlen): Set
Returns a subset of the currentSet
starting from a given key up to, but not including, the element at the provided length from the starting key - ->take(int $n): Set
Returns aSet
containing the firstn
values of the currentSet
- ->takeWhile((function(Tv): bool) $callback): Set
Returns aSet
containing the values of the currentSet
up to but not including the first value that producesfalse
when 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
Returns an immutable (ImmSet), deep copy of the currentSet
- ->toImmVector(): ImmVector
Returns an immutable vector (ImmVector) with the values of the currentSet
- ->toKeysArray(): varray
Returns anarray
containing the values from the currentSet
- ->toMap(): Map<arraykey, Tv>
Returns a Map based on the values of the currentSet
- ->toSet(): Set
Returns a deep copy of the currentSet
- ->toVArray(): varray
- ->toValuesArray(): varray
Returns anarray
containing the values from the currentSet
- ->toVector(): Vector
Returns a Vector of the currentSet
values - ->values(): Vector
Returns a Vector containing the values of the currentSet
- ->zip(Traversable $traversable): Set
Throws an exception unless the currentSet
or the Traversable is empty