The Vector class
(No version information available, might only be in Git)
Introduction
A Vector is a sequence of values in a contiguous buffer that grows and
shrinks automatically. Itâs the most efficient sequential structure because
a valueâs index is a direct mapping to its index in the buffer, and the
growth factor isn't bound to a specific multiple or exponent.
Strengths
- Supports array syntax (square brackets).
- Uses less overall memory than an array for the same number of values.
- Automatically frees allocated memory when its size drops low enough.
- Capacity does not have to be a power of 2.
-
get(),
set(),
push(),
pop() are all O(1).
Weaknesses
-
shift(),
unshift(),
insert() and
remove() are all O(n).
Class synopsis
Ds\Vector
implements Ds\Sequence
{
public allocate
(
int $capacity
) :
void
public clear
(
void
) :
void
public copy
(
void
) :
Ds\Vector
public insert
(
int $index
[,
mixed $...values
] ) :
void
public join
([
string $glue
] ) :
string
public rotate
(
int $rotations
) :
void
public set
(
int $index
,
mixed $value
) :
void
public slice
(
int $index
[,
int $length
] ) :
Ds\Vector
}
Predefined Constants
Ds\Vector::MIN_CAPACITY
-
Table of Contents
There are no user contributed notes for this page.