| Total Complexity | 16 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class BinaryNode implements Node |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var self|null |
||
| 13 | */ |
||
| 14 | private $parent; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var self|null |
||
| 18 | */ |
||
| 19 | private $left; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var self|null |
||
| 23 | */ |
||
| 24 | private $right; |
||
| 25 | |||
| 26 | public function parent(): ?self |
||
| 27 | { |
||
| 28 | return $this->parent; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function left(): ?self |
||
| 34 | } |
||
| 35 | |||
| 36 | public function right(): ?self |
||
| 37 | { |
||
| 38 | return $this->right; |
||
| 39 | } |
||
| 40 | |||
| 41 | public function height(): int |
||
| 44 | } |
||
| 45 | |||
| 46 | public function balance(): int |
||
| 47 | { |
||
| 48 | return ($this->right !== null ? $this->right->height() : 0) - ($this->left !== null ? $this->left->height() : 0); |
||
| 49 | } |
||
| 50 | |||
| 51 | public function setParent(?self $node = null): void |
||
| 52 | { |
||
| 53 | $this->parent = $node; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function attachLeft(self $node): void |
||
| 57 | { |
||
| 58 | $node->setParent($this); |
||
| 59 | $this->left = $node; |
||
| 60 | } |
||
| 61 | |||
| 62 | public function detachLeft(): void |
||
| 63 | { |
||
| 64 | if ($this->left !== null) { |
||
| 65 | $this->left->setParent(); |
||
| 66 | $this->left = null; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | public function attachRight(self $node): void |
||
| 71 | { |
||
| 72 | $node->setParent($this); |
||
| 73 | $this->right = $node; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function detachRight(): void |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 |