@@ -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 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace MartanLV\Koki; |
6 | 6 | |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return void |
22 | 22 | */ |
23 | - public function __construct(array $intervals = [], bool $preSorted = false) |
|
23 | + public function __construct(array $intervals = [ ], bool $preSorted = false) |
|
24 | 24 | { |
25 | - !$preSorted && usort($intervals, function (IntervalInterface $i0, IntervalInterface $i) { |
|
25 | + !$preSorted && usort($intervals, function(IntervalInterface $i0, IntervalInterface $i) { |
|
26 | 26 | return $i0->getStart() <=> $i->getStart(); |
27 | 27 | }); |
28 | 28 | $this->root = $this->toTree($intervals); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | return; |
44 | 44 | } |
45 | 45 | |
46 | - array_walk($intervals, function (IntervalInterface $el) use (&$max) { |
|
46 | + array_walk($intervals, function(IntervalInterface $el) use (&$max) { |
|
47 | 47 | if ($max < $el->getEnd()) { |
48 | 48 | $max = $el->getEnd(); |
49 | 49 | } |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function select(int $low, int $high): array |
74 | 74 | { |
75 | - return $this->root ? $this->root->select($low, $high) : []; |
|
75 | + return $this->root ? $this->root->select($low, $high) : [ ]; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | public function selectNode(int $low, int $high): array |
79 | 79 | { |
80 | - return $this->root ? $this->root->selectNode($low, $high) : []; |
|
80 | + return $this->root ? $this->root->selectNode($low, $high) : [ ]; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | { |
96 | 96 | $arr = $this->all(); |
97 | 97 | |
98 | - usort($arr, function (IntervalInterface $i0, IntervalInterface $i) { |
|
98 | + usort($arr, function(IntervalInterface $i0, IntervalInterface $i) { |
|
99 | 99 | return $i0->getStart() <=> $i->getStart(); |
100 | 100 | }); |
101 | 101 | |
@@ -104,22 +104,22 @@ discard block |
||
104 | 104 | |
105 | 105 | public function yieldInterSelect(int $low, int $high) |
106 | 106 | { |
107 | - return $this->root ? $this->root->yieldInterSelect($low, $high) : []; |
|
107 | + return $this->root ? $this->root->yieldInterSelect($low, $high) : [ ]; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | public function interSelectNode(int $low, int $high): array |
111 | 111 | { |
112 | - return $this->root ? $this->root->interSelectNode($low, $high) : []; |
|
112 | + return $this->root ? $this->root->interSelectNode($low, $high) : [ ]; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | public function interSelect(int $low, int $high): array |
116 | 116 | { |
117 | - return $this->root ? $this->root->interSelect($low, $high) : []; |
|
117 | + return $this->root ? $this->root->interSelect($low, $high) : [ ]; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | public function yieldSelect(int $low, int $high) |
121 | 121 | { |
122 | - return $this->root ? $this->root->yieldSelect($low, $high) : []; |
|
122 | + return $this->root ? $this->root->yieldSelect($low, $high) : [ ]; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function all(): array |
129 | 129 | { |
130 | - return $this->root ? $this->root->all() : []; |
|
130 | + return $this->root ? $this->root->all() : [ ]; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,15 +137,15 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function yieldAll() |
139 | 139 | { |
140 | - return $this->root ? $this->root->yieldAll() : []; |
|
140 | + return $this->root ? $this->root->yieldAll() : [ ]; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | public function removeRegion(int $low, int $high) |
144 | 144 | { |
145 | 145 | if (!$this->root) { |
146 | - return []; |
|
146 | + return [ ]; |
|
147 | 147 | } |
148 | - foreach($this->interSelectNode($low, $high) as $node) { |
|
148 | + foreach ($this->interSelectNode($low, $high) as $node) { |
|
149 | 149 | $this->remove($node); |
150 | 150 | } |
151 | 151 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | } |
189 | 189 | return; |
190 | 190 | if (!$this->root) { |
191 | - return []; |
|
191 | + return [ ]; |
|
192 | 192 | } |
193 | 193 | $this->root->remove($i); |
194 | 194 | } |
@@ -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 | } |