FixedArray::getGrowthFactor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace Mbh\Collection;
2
3
/**
4
 * MBHFramework
5
 *
6
 * @link      https://github.com/MBHFramework/mbh-framework
7
 * @copyright Copyright (c) 2017 Ulises Jeremias Cornejo Fandos
8
 * @license   https://github.com/MBHFramework/mbh-framework/blob/master/LICENSE (MIT License)
9
 */
10
11
use Mbh\Collection\Interfaces\Functional as FunctionalInterface;
12
use Mbh\Collection\Interfaces\Sequenceable as SequenceableInterface;
13
use Mbh\Interfaces\Allocated as AllocatedInterface;
14
use Mbh\Traits\Capacity;
15
use Mbh\Traits\EmptyGuard;
16
17
/**
18
 * The Fixed Array
19
 *
20
 * A FixedArray is a sequence of values in a contiguous buffer that grows and
21
 * shrinks automatically. It’s the most efficient sequential structure because
22
 * a value’s index is a direct mapping to its index in the buffer, and the
23
 * growth factor isn't bound to a specific multiple or exponent.
24
 *
25
 * @package structures
26
 * @author Ulises Jeremias Cornejo Fandos <[email protected]>
27
 */
28
class FixedArray implements AllocatedInterface, FunctionalInterface, SequenceableInterface
29
{
30
    use Capacity;
31
    use EmptyGuard;
32
    use Traits\Collection;
33
    use Traits\Functional;
34
    use Traits\Sequenceable;
35
    use Traits\Sequenceable\Arrayed;
36
37
    const MIN_CAPACITY = 8.0;
38
39
    /**
40
     * @inheritDoc
41
     */
42
    protected function getGrowthFactor(): float
43
    {
44
        return 1.5;
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    protected function shouldIncreaseCapacity(): bool
51
    {
52
        return count($this) > $this->getSize();
53
    }
54
}
55