@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class Tree extends Node |
| 14 | 14 | { |
| 15 | - public $root; |
|
| 15 | + public $root; |
|
| 16 | 16 | /** |
| 17 | 17 | * undocumented function. |
| 18 | 18 | * |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | $max |
| 61 | 61 | ); |
| 62 | 62 | |
| 63 | - $node->root = &$this; |
|
| 64 | - return $node; |
|
| 63 | + $node->root = &$this; |
|
| 64 | + return $node; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function balance() |
| 87 | 87 | { |
| 88 | - // todo |
|
| 88 | + // todo |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -142,63 +142,63 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | public function removeRegion(int $low, int $high) |
| 144 | 144 | { |
| 145 | - if (!$this->root) { |
|
| 146 | - return []; |
|
| 147 | - } |
|
| 148 | - foreach($this->interSelectNode($low, $high) as $node) { |
|
| 149 | - $this->remove($node); |
|
| 150 | - } |
|
| 145 | + if (!$this->root) { |
|
| 146 | + return []; |
|
| 147 | + } |
|
| 148 | + foreach($this->interSelectNode($low, $high) as $node) { |
|
| 149 | + $this->remove($node); |
|
| 150 | + } |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | public function remove(IntervalInterface $i) |
| 154 | 154 | { |
| 155 | - if (!$i->left && !$i->right) { |
|
| 156 | - if ($i->root) { |
|
| 157 | - $i->root = null; |
|
| 158 | - } |
|
| 159 | - return; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if ($i->left && $i->right) { |
|
| 163 | - // todo |
|
| 164 | - return; |
|
| 165 | - } |
|
| 166 | - if ($i->left) { |
|
| 167 | - $i->interval = &$i->left->interval; |
|
| 168 | - $i->left = null; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - if ($i->right) { |
|
| 172 | - |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ($this->max > $i->getEnd()) { |
|
| 176 | - if ($this->left) { |
|
| 177 | - $this->left->add($i); |
|
| 178 | - } else { |
|
| 179 | - $this->left = new Node($i); |
|
| 180 | - } |
|
| 181 | - } else { |
|
| 182 | - $this->max = $i->getEnd(); |
|
| 183 | - if ($this->right) { |
|
| 184 | - $this->right->add($i); |
|
| 185 | - } else { |
|
| 186 | - $this->right = new Node($i); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - return; |
|
| 190 | - if (!$this->root) { |
|
| 191 | - return []; |
|
| 192 | - } |
|
| 193 | - $this->root->remove($i); |
|
| 155 | + if (!$i->left && !$i->right) { |
|
| 156 | + if ($i->root) { |
|
| 157 | + $i->root = null; |
|
| 158 | + } |
|
| 159 | + return; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if ($i->left && $i->right) { |
|
| 163 | + // todo |
|
| 164 | + return; |
|
| 165 | + } |
|
| 166 | + if ($i->left) { |
|
| 167 | + $i->interval = &$i->left->interval; |
|
| 168 | + $i->left = null; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + if ($i->right) { |
|
| 172 | + |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($this->max > $i->getEnd()) { |
|
| 176 | + if ($this->left) { |
|
| 177 | + $this->left->add($i); |
|
| 178 | + } else { |
|
| 179 | + $this->left = new Node($i); |
|
| 180 | + } |
|
| 181 | + } else { |
|
| 182 | + $this->max = $i->getEnd(); |
|
| 183 | + if ($this->right) { |
|
| 184 | + $this->right->add($i); |
|
| 185 | + } else { |
|
| 186 | + $this->right = new Node($i); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + return; |
|
| 190 | + if (!$this->root) { |
|
| 191 | + return []; |
|
| 192 | + } |
|
| 193 | + $this->root->remove($i); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | public function add(IntervalInterface $i) |
| 197 | 197 | { |
| 198 | - if (!$this->root) { |
|
| 199 | - $this->root = new Node($i); |
|
| 200 | - return; |
|
| 201 | - } |
|
| 202 | - $this->root->add($i); |
|
| 198 | + if (!$this->root) { |
|
| 199 | + $this->root = new Node($i); |
|
| 200 | + return; |
|
| 201 | + } |
|
| 202 | + $this->root->add($i); |
|
| 203 | 203 | } |
| 204 | 204 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class Node |
| 13 | 13 | { |
| 14 | - public $root; |
|
| 14 | + public $root; |
|
| 15 | 15 | /** |
| 16 | 16 | * @var Interval |
| 17 | 17 | */ |
@@ -208,39 +208,39 @@ discard block |
||
| 208 | 208 | |
| 209 | 209 | public function remove() |
| 210 | 210 | { |
| 211 | - if ($this->max > $i->getEnd()) { |
|
| 212 | - if ($this->left) { |
|
| 213 | - $this->left->add($i); |
|
| 214 | - } else { |
|
| 215 | - $this->left = new Node($i); |
|
| 216 | - } |
|
| 217 | - } else { |
|
| 218 | - $this->max = $i->getEnd(); |
|
| 219 | - if ($this->right) { |
|
| 220 | - $this->right->add($i); |
|
| 221 | - } else { |
|
| 222 | - $this->right = new Node($i); |
|
| 223 | - } |
|
| 224 | - } |
|
| 211 | + if ($this->max > $i->getEnd()) { |
|
| 212 | + if ($this->left) { |
|
| 213 | + $this->left->add($i); |
|
| 214 | + } else { |
|
| 215 | + $this->left = new Node($i); |
|
| 216 | + } |
|
| 217 | + } else { |
|
| 218 | + $this->max = $i->getEnd(); |
|
| 219 | + if ($this->right) { |
|
| 220 | + $this->right->add($i); |
|
| 221 | + } else { |
|
| 222 | + $this->right = new Node($i); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | public function add(IntervalInterface $i) |
| 228 | 228 | { |
| 229 | - if ($this->max > $i->getEnd()) { |
|
| 230 | - if ($this->left) { |
|
| 231 | - $this->left->add($i); |
|
| 232 | - } else { |
|
| 233 | - $this->left = new Node($i); |
|
| 234 | - $this->left->root = &$this; |
|
| 235 | - } |
|
| 236 | - } else { |
|
| 237 | - $this->max = $i->getEnd(); |
|
| 238 | - if ($this->right) { |
|
| 239 | - $this->right->add($i); |
|
| 240 | - } else { |
|
| 241 | - $this->right = new Node($i); |
|
| 242 | - $this->right->root = &$this; |
|
| 243 | - } |
|
| 244 | - } |
|
| 229 | + if ($this->max > $i->getEnd()) { |
|
| 230 | + if ($this->left) { |
|
| 231 | + $this->left->add($i); |
|
| 232 | + } else { |
|
| 233 | + $this->left = new Node($i); |
|
| 234 | + $this->left->root = &$this; |
|
| 235 | + } |
|
| 236 | + } else { |
|
| 237 | + $this->max = $i->getEnd(); |
|
| 238 | + if ($this->right) { |
|
| 239 | + $this->right->add($i); |
|
| 240 | + } else { |
|
| 241 | + $this->right = new Node($i); |
|
| 242 | + $this->right->root = &$this; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | 245 | } |
| 246 | 246 | } |