The Set class

(PECL ds >= 1.0.0)

Einführung

A Set is a sequence of unique values. This implementation uses the same hash table as Ds\Map, where values are used as keys and the mapped value is ignored.

Strengths

  • Values can be any type, including objects.
  • Supports array syntax (square brackets).
  • Insertion order is preserved.
  • Automatically frees allocated memory when its size drops low enough.
  • add(), remove() and contains() are all O(1).

Weaknesses

  • Doesn’t support push(), pop(), insert(), shift(), or unshift().
  • get() is O(n) if there are deleted values in the buffer before the accessed index, O(1) otherwise.

Klassenbeschreibung

class Ds\Set implements Ds\Collection, ArrayAccess {
/* Konstanten */
const int MIN_CAPACITY = 8;
/* Methoden */
public function add(mixed ...$values): void
public function allocate(int $capacity): void
public function capacity(): int
public function clear(): void
public function contains(mixed ...$values): bool
public function copy(): Ds\Set
public function diff(Ds\Set $set): Ds\Set
public function filter(callable $callback = ?): Ds\Set
public function first(): mixed
public function get(int $index): mixed
public function intersect(Ds\Set $set): Ds\Set
public function isEmpty(): bool
public function join(string $glue = ?): string
public function last(): mixed
public function map(callable $callback): Ds\Set
public function merge(mixed $values): Ds\Set
public function reduce(callable $callback, mixed $initial = ?): mixed
public function remove(mixed ...$values): void
public function reverse(): void
public function reversed(): Ds\Set
public function slice(int $index, int $length = ?): Ds\Set
public function sort(callable $comparator = ?): void
public function sorted(callable $comparator = ?): Ds\Set
public function sum(): int|float
public function toArray(): array
public function union(Ds\Set $set): Ds\Set
public function xor(Ds\Set $set): Ds\Set
}

Vordefinierte Konstanten

Ds\Set::MIN_CAPACITY

Changelog

Version Beschreibung
PECL ds 1.3.0 The class now implements ArrayAccess.
PECL ds 1.2.7 Added the Ds\Set::map() method.
PECL ds 1.2.0 Ds\Set::MIN_CAPACITY changed from 16 to 8.

Inhaltsverzeichnis