1 | <?php |
||
9 | trait Capacity |
||
10 | { |
||
11 | /** |
||
12 | * @var int internal capacity |
||
13 | */ |
||
14 | private $capacity = self::MIN_CAPACITY; |
||
15 | |||
16 | /** |
||
17 | * Returns the current capacity. |
||
18 | * |
||
19 | * @return int |
||
20 | */ |
||
21 | 63 | 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 | 12 | public function allocate(int $capacity) |
|
38 | |||
39 | /** |
||
40 | * Called when capacity should be increased to accommodate new values. |
||
41 | */ |
||
42 | abstract protected function increaseCapacity(); |
||
43 | |||
44 | /** |
||
45 | * Adjusts the structure's capacity according to its current size. |
||
46 | */ |
||
47 | 1922 | private function adjustCapacity() |
|
63 | } |
||
64 |