자료구조 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를 구현합니다. |
목차
- Ds\Set::add — Adds values to the set
- Ds\Set::allocate — Allocates enough memory for a required capacity
- Ds\Set::capacity — Returns the current capacity
- Ds\Set::clear — Removes all values
- Ds\Set::__construct — Creates a new instance
- Ds\Set::contains — Determines if the set contains all values
- Ds\Set::copy — Returns a shallow copy of the set
- Ds\Set::count — Returns the number of values in the set
- Ds\Set::diff — Creates a new set using values that aren't in another set
- Ds\Set::filter — Creates a new set using a callable to determine which values to include
- Ds\Set::first — Returns the first value in the set
- Ds\Set::get — Returns the value at a given index
- Ds\Set::intersect — Creates a new set by intersecting values with another set
- Ds\Set::isEmpty — Returns whether the set is empty
- Ds\Set::join — Joins all values together as a string
- Ds\Set::jsonSerialize — Returns a representation that can be converted to JSON
- Ds\Set::last — Returns the last value in the set
- Ds\Set::merge — Returns the result of adding all given values to the set
- Ds\Set::reduce — Reduces the set to a single value using a callback function
- Ds\Set::remove — Removes all given values from the set
- Ds\Set::reverse — Reverses the set in-place
- Ds\Set::reversed — Returns a reversed copy
- Ds\Set::slice — Returns a sub-set of a given range
- Ds\Set::sort — Sorts the set in-place
- Ds\Set::sorted — Returns a sorted copy
- Ds\Set::sum — Returns the sum of all values in the set
- Ds\Set::toArray — Converts the set to an array
- Ds\Set::union — Creates a new set using values from the current instance and another set
- Ds\Set::xor — Creates a new set using values in either the current instance or in another set, but not in both