| Total Complexity | 9 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class Functions |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Checks if the number is a power of 2 |
||
| 20 | * |
||
| 21 | * @param int $x |
||
| 22 | * |
||
| 23 | * @return bool |
||
| 24 | */ |
||
| 25 | 12 | public static function isPowerOf2(int $x) : bool { |
|
| 26 | 12 | return ($x !== 0) && ($x & ($x - 1)) === 0; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Get the next power of 2 larger than input |
||
| 31 | * |
||
| 32 | * @param int $x |
||
| 33 | * |
||
| 34 | * @return int |
||
| 35 | */ |
||
| 36 | 9 | public static function nextPowerOf2(int $x) : int { |
|
| 37 | // Left bit shift by the bit length of the previous number |
||
| 38 | 9 | return 1 << strlen(decbin($x)); |
|
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get the previous power of 2 smaller or equal than input |
||
| 43 | * |
||
| 44 | * @param int $x |
||
| 45 | * |
||
| 46 | * @return int |
||
| 47 | */ |
||
| 48 | 9 | public static function previousPowerOf2(int $x) : int { |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Calculate a count of 2D array |
||
| 55 | * |
||
| 56 | * @param array[] $array |
||
| 57 | * |
||
| 58 | * @return int |
||
| 59 | */ |
||
| 60 | 10 | public static function nestedCount(array $array) : int { |
|
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param array $array |
||
| 70 | * |
||
| 71 | * @return array |
||
| 72 | */ |
||
| 73 | 4 | public static function sortAlternate(array &$array) : array { |
|
| 89 | } |
||
| 90 | } |