자료구조 Set 클래스

(사용 가능한 버전 정보가 없으며 Git에만 있을 수 있음)


소개

집합은 고유한 값의 시퀀스입니다. 이 구현은 Ds\Map과 동일한 해시 테이블을 사용합니다. 여기서 값은 키로 사용되고 매핑된 값은 무시됩니다.


강점

  • 값은 개체를 포함하여 모든 유형이 될 수 있습니다.
  • 배열 구문(대괄호)을 지원합니다.
  • 게재 순위가 유지됩니다.
  • 크기가 충분히 낮아지면 할당된 메모리를 자동으로 해제합니다.
  • add(), remove(), contains()은 모두 O(1)입니다.

약점
  • push(), pop(), insert(), shift() 또는 unshift()를 지원하지 않습니다.
  • get()은 액세스된 인덱스 이전에 버퍼에 삭제된 값이 있으면 O(n)이고, 그렇지 않으면 O(1)입니다.


클래스 개요

                  
class Ds\Set implements Ds\Collection, ArrayAccess {

  /* Constants */
  const int MIN_CAPACITY = 16;

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

미리 정의된 상수

Ds\Set::MIN_CAPACITY

변경 로그

버전 설명
PECL ds 1.3.0 클래스는 이제 ArrayAccess를 구현합니다.

목차