| 1 | <?php |
||
| 8 | class Bitmask |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var int |
||
| 12 | */ |
||
| 13 | const MAX_BIT = 63; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var int |
||
| 17 | */ |
||
| 18 | private $mask; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param int $mask |
||
| 22 | */ |
||
| 23 | 11 | public function __construct($mask = 0) |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param int $mask |
||
| 30 | * @return $this |
||
| 31 | */ |
||
| 32 | 1 | public static function create($mask = 0) |
|
| 33 | { |
||
| 34 | 1 | return new self($mask); |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param int $bit |
||
| 39 | * @return $this |
||
| 40 | */ |
||
| 41 | 5 | public function setBit($bit) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * @param int $mask |
||
| 48 | * @return $this |
||
| 49 | */ |
||
| 50 | 5 | public function addMask($mask) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @param int $bit |
||
| 58 | * @return int |
||
| 59 | * @throws \InvalidArgumentException |
||
| 60 | */ |
||
| 61 | 6 | private function checkBit($bit) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @param int $bit |
||
| 75 | * @return $this |
||
| 76 | */ |
||
| 77 | 1 | public function unsetBit($bit) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * @param int $mask |
||
| 84 | * @return $this |
||
| 85 | */ |
||
| 86 | 2 | public function deleteMask($mask) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * @param int $bit |
||
| 94 | * @return bool |
||
| 95 | */ |
||
| 96 | 5 | public function issetBit($bit) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * @return int |
||
| 103 | */ |
||
| 104 | 9 | public function getMask() |
|
| 108 | |||
| 109 | /** |
||
| 110 | * @param int $mask |
||
| 111 | * @return $this |
||
| 112 | */ |
||
| 113 | 11 | public function setMask($mask) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Return set bits count. |
||
| 121 | * Actually, counts the number of 1 in binary representation of the decimal mask integer. |
||
| 122 | * @return int |
||
| 123 | */ |
||
| 124 | 5 | public function getSetBitsCount() |
|
| 128 | } |
||
| 129 |