The Set class

(No version information available, might only be in Git)

はじめに

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.

クラス概要

Ds\Setimplements Ds\Collection, ArrayAccess {
constintMIN_CAPACITY = 16 ;
publicadd(mixed...$values): void
publicallocate(int$capacity): void
publiccapacity(): int
publicclear(): void
publiccontains(mixed...$values): bool
publiccopy(): Ds\Set
publicdiff(Ds\Set$set): Ds\Set
publicfilter(callable$callback = ?): Ds\Set
publicfirst(): mixed
publicget(int$index): mixed
publicintersect(Ds\Set$set): Ds\Set
publicisEmpty(): bool
publicjoin(string$glue = ?): string
publiclast(): mixed
publicmerge(mixed$values): Ds\Set
publicreduce(callable$callback, mixed$initial = ?): mixed
publicremove(mixed...$values): void
publicreverse(): void
publicreversed(): Ds\Set
publicslice(int$index, int$length = ?): Ds\Set
publicsort(callable$comparator = ?): void
publicsorted(callable$comparator = ?): Ds\Set
publicsum(): int|float
publictoArray(): array
publicunion(Ds\Set$set): Ds\Set
publicxor(Ds\Set$set): Ds\Set
}

定義済み定数

Ds\Set::MIN_CAPACITY

変更履歴

バージョン説明
PECL ds 1.3.0 The class now implements ArrayAccess.

目次