1 | <?php |
||
9 | trait Capacity |
||
10 | { |
||
11 | /** |
||
12 | * @var integer internal capacity |
||
13 | */ |
||
14 | private $capacity = self::MIN_CAPACITY; |
||
15 | |||
16 | /** |
||
17 | * Returns the current capacity. |
||
18 | * |
||
19 | * @return int |
||
20 | */ |
||
21 | public function capacity(): int |
||
25 | |||
26 | /** |
||
27 | * Ensures that enough memory is allocated for a specified capacity. This |
||
28 | * potentially reduces the number of reallocations as the size increases. |
||
29 | * |
||
30 | * @param int $capacity The number of values for which capacity should be |
||
31 | * allocated. Capacity will stay the same if this value |
||
32 | * is less than or equal to the current capacity. |
||
33 | */ |
||
34 | public function allocate(int $capacity) |
||
38 | |||
39 | /** |
||
40 | * @return the structures growth factor. |
||
|
|||
41 | */ |
||
42 | protected function getGrowthFactor(): float |
||
46 | |||
47 | /** |
||
48 | * @return float to multiply by when decreasing capacity. |
||
49 | */ |
||
50 | protected function getDecayFactor(): float |
||
54 | |||
55 | /** |
||
56 | * @return float the ratio between size and capacity when capacity should be |
||
57 | * decreased. |
||
58 | */ |
||
59 | protected function getTruncateThreshold(): float |
||
63 | |||
64 | /** |
||
65 | * Checks and adjusts capacity if required. |
||
66 | */ |
||
67 | protected function checkCapacity() |
||
77 | |||
78 | /** |
||
79 | * Called when capacity should be increased to accommodate new values. |
||
80 | */ |
||
81 | protected function increaseCapacity() |
||
85 | |||
86 | /** |
||
87 | * Called when capacity should be decrease if it drops below a threshold. |
||
88 | */ |
||
89 | protected function decreaseCapacity() |
||
93 | |||
94 | /** |
||
95 | * @return whether capacity should be increased. |
||
96 | */ |
||
97 | protected function shouldDecreaseCapacity(): bool |
||
101 | |||
102 | /** |
||
103 | * @return whether capacity should be increased. |
||
104 | */ |
||
105 | protected function shouldIncreaseCapacity(): bool |
||
109 | } |
||
110 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.