자료구조 Vector 클래스

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


소개

Vector는 자동으로 늘어나고 축소되는 연속 버퍼의 값 시퀀스입니다. 값의 인덱스가 버퍼의 인덱스에 직접 매핑되고 성장 인자가 특정 배수 또는 지수에 구속되지 않기 때문에 가장 효율적인 순차 구조입니다.


강점

  • 배열 구문(대괄호)을 지원합니다.
  • 동일한 수의 값에 대해 배열보다 적은 전체 메모리를 사용합니다.
  • 크기가 충분히 낮아지면 할당된 메모리를 자동으로 해제합니다.
  • 용량이 2의 거듭제곱일 필요는 없습니다.
  • get(), set(), push(), pop()은 모두 O(1)입니다.

약점
  • shift(), unshift(), insert()remove()는 모두 O(n)입니다.


클래스 개요

                  
class Ds\Vector implements Ds\Sequence, ArrayAccess {

  /* Constants */
  const int MIN_CAPACITY = 10;

  /* Methods */
  public allocate(int $capacity): void
  public apply(callable $callback): void
  public capacity(): int
  public clear(): void
  public contains(mixed ...$values): bool
  public copy(): Ds\Vector
  public filter(callable $callback = ?): Ds\Vector
  public find(mixed $value): mixed
  public first(): mixed
  public get(int $index): mixed
  public insert(int $index, mixed ...$values): void
  public isEmpty(): bool
  public join(string $glue = ?): string
  public last(): mixed
  public map(callable $callback): Ds\Vector
  public merge(mixed $values): Ds\Vector
  public pop(): mixed
  public push(mixed ...$values): void
  public reduce(callable $callback, mixed $initial = ?): mixed
  public remove(int $index): mixed
  public reverse(): void
  public reversed(): Ds\Vector
  public rotate(int $rotations): void
  public set(int $index, mixed $value): void
  public shift(): mixed
  public slice(int $index, int $length = ?): Ds\Vector
  public sort(callable $comparator = ?): void
  public sorted(callable $comparator = ?): Ds\Vector
  public sum(): int|float
  public toArray(): array
  public unshift(mixed $values = ?): void
}
                  
                

미리 정의된 상수

Ds\Vector::MIN_CAPACITY

변경 로그

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

목차