-
Notifications
You must be signed in to change notification settings - Fork 45
/
Vector.php
37 lines (33 loc) · 941 Bytes
/
Vector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Ds;
/**
* 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.
*
* @package Ds
*
* @template TValue
* @implements Sequence<TValue>
* @template-use Traits\GenericCollection<int, TValue>
* @template-use Traits\GenericSequence<TValue>
*/
final class Vector implements Sequence
{
use Traits\GenericCollection;
use Traits\GenericSequence;
use Traits\Capacity;
public const MIN_CAPACITY = 8;
protected function getGrowthFactor(): float
{
return 1.5;
}
/**
* @return bool whether capacity should be increased.
*/
protected function shouldIncreaseCapacity(): bool
{
return count($this) > $this->capacity;
}
}