@@ -274,8 +274,7 @@ |
||
| 274 | 274 | try |
| 275 | 275 | { |
| 276 | 276 | return (bool) $this->map->find($element); |
| 277 | - } |
|
| 278 | - catch (\OutOfBoundsException $e) |
|
| 277 | + } catch (\OutOfBoundsException $e) |
|
| 279 | 278 | { |
| 280 | 279 | return false; |
| 281 | 280 | } |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | { |
| 68 | 68 | if ($comparator == null) |
| 69 | 69 | { |
| 70 | - $this->comparator = function ($key1, $key2) |
|
| 70 | + $this->comparator = function($key1, $key2) |
|
| 71 | 71 | { |
| 72 | 72 | return $key1 - $key2; |
| 73 | 73 | }; |
@@ -71,8 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | return $key1 - $key2; |
| 73 | 73 | }; |
| 74 | - } |
|
| 75 | - else |
|
| 74 | + } else |
|
| 76 | 75 | { |
| 77 | 76 | $this->comparator = $comparator; |
| 78 | 77 | } |
@@ -118,8 +117,7 @@ discard block |
||
| 118 | 117 | if ($this->root) |
| 119 | 118 | { |
| 120 | 119 | return $this->root->first; |
| 121 | - } |
|
| 122 | - else |
|
| 120 | + } else |
|
| 123 | 121 | { |
| 124 | 122 | throw new \OutOfBoundsException('First element unexisting'); |
| 125 | 123 | } |
@@ -139,8 +137,7 @@ discard block |
||
| 139 | 137 | if ($this->root) |
| 140 | 138 | { |
| 141 | 139 | return $this->root->last; |
| 142 | - } |
|
| 143 | - else |
|
| 140 | + } else |
|
| 144 | 141 | { |
| 145 | 142 | throw new \OutOfBoundsException('Last element unexisting'); |
| 146 | 143 | } |
@@ -164,8 +161,7 @@ discard block |
||
| 164 | 161 | if ($predecessor) |
| 165 | 162 | { |
| 166 | 163 | return $predecessor; |
| 167 | - } |
|
| 168 | - else |
|
| 164 | + } else |
|
| 169 | 165 | { |
| 170 | 166 | throw new \OutOfBoundsException('Predecessor element unexisting'); |
| 171 | 167 | } |
@@ -189,8 +185,7 @@ discard block |
||
| 189 | 185 | if ($successor) |
| 190 | 186 | { |
| 191 | 187 | return $successor; |
| 192 | - } |
|
| 193 | - else |
|
| 188 | + } else |
|
| 194 | 189 | { |
| 195 | 190 | throw new \OutOfBoundsException('Successor element unexisting'); |
| 196 | 191 | } |
@@ -212,8 +207,7 @@ discard block |
||
| 212 | 207 | if ($this->root) |
| 213 | 208 | { |
| 214 | 209 | $lower = $this->root->find($key, $this->comparator, -2); |
| 215 | - } |
|
| 216 | - else |
|
| 210 | + } else |
|
| 217 | 211 | { |
| 218 | 212 | $lower = null; |
| 219 | 213 | } |
@@ -221,8 +215,7 @@ discard block |
||
| 221 | 215 | if ($lower) |
| 222 | 216 | { |
| 223 | 217 | return $lower; |
| 224 | - } |
|
| 225 | - else |
|
| 218 | + } else |
|
| 226 | 219 | { |
| 227 | 220 | throw new \OutOfBoundsException('Lower element unexisting'); |
| 228 | 221 | } |
@@ -244,8 +237,7 @@ discard block |
||
| 244 | 237 | if ($this->root) |
| 245 | 238 | { |
| 246 | 239 | $floor = $this->root->find($key, $this->comparator, -1); |
| 247 | - } |
|
| 248 | - else |
|
| 240 | + } else |
|
| 249 | 241 | { |
| 250 | 242 | $floor = null; |
| 251 | 243 | } |
@@ -253,8 +245,7 @@ discard block |
||
| 253 | 245 | if ($floor) |
| 254 | 246 | { |
| 255 | 247 | return $floor; |
| 256 | - } |
|
| 257 | - else |
|
| 248 | + } else |
|
| 258 | 249 | { |
| 259 | 250 | throw new \OutOfBoundsException('Floor element unexisting'); |
| 260 | 251 | } |
@@ -276,8 +267,7 @@ discard block |
||
| 276 | 267 | if ($this->root) |
| 277 | 268 | { |
| 278 | 269 | $find = $this->root->find($key, $this->comparator, 0); |
| 279 | - } |
|
| 280 | - else |
|
| 270 | + } else |
|
| 281 | 271 | { |
| 282 | 272 | $find = null; |
| 283 | 273 | } |
@@ -285,8 +275,7 @@ discard block |
||
| 285 | 275 | if ($find) |
| 286 | 276 | { |
| 287 | 277 | return $find; |
| 288 | - } |
|
| 289 | - else |
|
| 278 | + } else |
|
| 290 | 279 | { |
| 291 | 280 | throw new \OutOfBoundsException('Element unexisting'); |
| 292 | 281 | } |
@@ -308,8 +297,7 @@ discard block |
||
| 308 | 297 | if ($this->root) |
| 309 | 298 | { |
| 310 | 299 | $ceiling = $this->root->find($key, $this->comparator, 1); |
| 311 | - } |
|
| 312 | - else |
|
| 300 | + } else |
|
| 313 | 301 | { |
| 314 | 302 | $ceiling = null; |
| 315 | 303 | } |
@@ -317,8 +305,7 @@ discard block |
||
| 317 | 305 | if ($ceiling) |
| 318 | 306 | { |
| 319 | 307 | return $ceiling; |
| 320 | - } |
|
| 321 | - else |
|
| 308 | + } else |
|
| 322 | 309 | { |
| 323 | 310 | throw new \OutOfBoundsException('Ceiling element unexisting'); |
| 324 | 311 | } |
@@ -340,8 +327,7 @@ discard block |
||
| 340 | 327 | if ($this->root) |
| 341 | 328 | { |
| 342 | 329 | $higher = $this->root->find($key, $this->comparator, 2); |
| 343 | - } |
|
| 344 | - else |
|
| 330 | + } else |
|
| 345 | 331 | { |
| 346 | 332 | $higher = null; |
| 347 | 333 | } |
@@ -349,8 +335,7 @@ discard block |
||
| 349 | 335 | if ($higher) |
| 350 | 336 | { |
| 351 | 337 | return $higher; |
| 352 | - } |
|
| 353 | - else |
|
| 338 | + } else |
|
| 354 | 339 | { |
| 355 | 340 | throw new \OutOfBoundsException('Higher element unexisting'); |
| 356 | 341 | } |
@@ -460,8 +445,7 @@ discard block |
||
| 460 | 445 | if ($this->root) |
| 461 | 446 | { |
| 462 | 447 | $this->root = $this->root->insert($key, $value, $this->comparator); |
| 463 | - } |
|
| 464 | - else |
|
| 448 | + } else |
|
| 465 | 449 | { |
| 466 | 450 | $this->root = TreeNode::create($key, $value); |
| 467 | 451 | } |
@@ -496,8 +480,7 @@ discard block |
||
| 496 | 480 | if ($this->root) |
| 497 | 481 | { |
| 498 | 482 | return count($this->root); |
| 499 | - } |
|
| 500 | - else |
|
| 483 | + } else |
|
| 501 | 484 | { |
| 502 | 485 | return 0; |
| 503 | 486 | } |
@@ -131,8 +131,7 @@ |
||
| 131 | 131 | if ($value) |
| 132 | 132 | { |
| 133 | 133 | $map[$element] = true; |
| 134 | - } |
|
| 135 | - else |
|
| 134 | + } else |
|
| 136 | 135 | { |
| 137 | 136 | unset($map[$element]); |
| 138 | 137 | } |
@@ -385,8 +385,7 @@ discard block |
||
| 385 | 385 | try |
| 386 | 386 | { |
| 387 | 387 | return $this->find($key)->value; |
| 388 | - } |
|
| 389 | - catch (\OutOfBoundsException $e) |
|
| 388 | + } catch (\OutOfBoundsException $e) |
|
| 390 | 389 | { |
| 391 | 390 | throw new \OutOfRangeException('Undefined offset'); |
| 392 | 391 | } |
@@ -406,8 +405,7 @@ discard block |
||
| 406 | 405 | try |
| 407 | 406 | { |
| 408 | 407 | return (bool) $this->find($key); |
| 409 | - } |
|
| 410 | - catch (\OutOfBoundsException $e) |
|
| 408 | + } catch (\OutOfBoundsException $e) |
|
| 411 | 409 | { |
| 412 | 410 | return false; |
| 413 | 411 | } |
@@ -143,8 +143,7 @@ discard block |
||
| 143 | 143 | try |
| 144 | 144 | { |
| 145 | 145 | $this->current = $this->map->first(); |
| 146 | - } |
|
| 147 | - catch (\OutOfBoundsException $e) |
|
| 146 | + } catch (\OutOfBoundsException $e) |
|
| 148 | 147 | { |
| 149 | 148 | $this->current = null; |
| 150 | 149 | } |
@@ -162,8 +161,7 @@ discard block |
||
| 162 | 161 | if ($this->type == self::PAIRS) |
| 163 | 162 | { |
| 164 | 163 | return $this->current->key; |
| 165 | - } |
|
| 166 | - else |
|
| 164 | + } else |
|
| 167 | 165 | { |
| 168 | 166 | return $this->index; |
| 169 | 167 | } |
@@ -181,8 +179,7 @@ discard block |
||
| 181 | 179 | if ($this->type == self::KEYS) |
| 182 | 180 | { |
| 183 | 181 | return $this->current->key; |
| 184 | - } |
|
| 185 | - else |
|
| 182 | + } else |
|
| 186 | 183 | { |
| 187 | 184 | return $this->current->value; |
| 188 | 185 | } |
@@ -200,8 +197,7 @@ discard block |
||
| 200 | 197 | try |
| 201 | 198 | { |
| 202 | 199 | $this->current = $this->map->successor($this->current); |
| 203 | - } |
|
| 204 | - catch (\OutOfBoundsException $e) |
|
| 200 | + } catch (\OutOfBoundsException $e) |
|
| 205 | 201 | { |
| 206 | 202 | $this->current = null; |
| 207 | 203 | } |
@@ -67,9 +67,9 @@ |
||
| 67 | 67 | protected function __construct(SortedMap $map) |
| 68 | 68 | { |
| 69 | 69 | $this->map = $map; |
| 70 | - $this->comparator = function ($key1, $key2) |
|
| 70 | + $this->comparator = function($key1, $key2) |
|
| 71 | 71 | { |
| 72 | - return - call_user_func($this->map->comparator, $key1, $key2); |
|
| 72 | + return -call_user_func($this->map->comparator, $key1, $key2); |
|
| 73 | 73 | }; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -14,14 +14,14 @@ discard block |
||
| 14 | 14 | * This file is part of the php-sorted-collections package https://github.com/chdemko/php-sorted-collections |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -require __DIR__ . '/../vendor/autoload.php'; |
|
| 17 | +require __DIR__.'/../vendor/autoload.php'; |
|
| 18 | 18 | |
| 19 | 19 | use chdemko\SortedCollection\TreeMap; |
| 20 | 20 | |
| 21 | 21 | date_default_timezone_set('UTC'); |
| 22 | -printf('TreeMap benchmarking run on ' . date('r') . PHP_EOL . PHP_EOL); |
|
| 23 | -printf('%25s %10s %10s %10s' . PHP_EOL, 'Operation', 'n', 'seconds', 'μs/(n log(n))'); |
|
| 24 | -printf('-------------------------------------------------------------' . PHP_EOL); |
|
| 22 | +printf('TreeMap benchmarking run on '.date('r').PHP_EOL.PHP_EOL); |
|
| 23 | +printf('%25s %10s %10s %10s'.PHP_EOL, 'Operation', 'n', 'seconds', 'μs/(n log(n))'); |
|
| 24 | +printf('-------------------------------------------------------------'.PHP_EOL); |
|
| 25 | 25 | |
| 26 | 26 | $tree = TreeMap::create(); |
| 27 | 27 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $end = microtime(true); |
| 38 | 38 | |
| 39 | 39 | printf( |
| 40 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 40 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 41 | 41 | 'Insert all elements', |
| 42 | 42 | $count, |
| 43 | 43 | $end - $start, |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $end = microtime(true); |
| 65 | 65 | |
| 66 | 66 | printf( |
| 67 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 67 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 68 | 68 | 'Remove all elements', |
| 69 | 69 | $count, |
| 70 | 70 | $end - $start, |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $end = microtime(true); |
| 92 | 92 | |
| 93 | 93 | printf( |
| 94 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 94 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 95 | 95 | 'Search all elements', |
| 96 | 96 | $count, |
| 97 | 97 | $end - $start, |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $end = microtime(true); |
| 118 | 118 | |
| 119 | 119 | printf( |
| 120 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 120 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 121 | 121 | 'Loop on all elements', |
| 122 | 122 | $count, |
| 123 | 123 | $end - $start, |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $end = microtime(true); |
| 142 | 142 | |
| 143 | 143 | printf( |
| 144 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 144 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 145 | 145 | 'Count all elements', |
| 146 | 146 | $count, |
| 147 | 147 | $end - $start, |
@@ -14,15 +14,15 @@ discard block |
||
| 14 | 14 | * This file is part of the php-sorted-collections package https://github.com/chdemko/php-sorted-collections |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -require __DIR__ . '/../vendor/autoload.php'; |
|
| 17 | +require __DIR__.'/../vendor/autoload.php'; |
|
| 18 | 18 | |
| 19 | 19 | use chdemko\SortedCollection\TreeMap; |
| 20 | 20 | use chdemko\SortedCollection\ReversedMap; |
| 21 | 21 | |
| 22 | 22 | date_default_timezone_set('UTC'); |
| 23 | -printf('ReversedMap benchmarking run on ' . date('r') . PHP_EOL . PHP_EOL); |
|
| 24 | -printf('%25s %10s %10s %10s' . PHP_EOL, 'Operation', 'n', 'seconds', 'μs/(n log(n))'); |
|
| 25 | -printf('-------------------------------------------------------------' . PHP_EOL); |
|
| 23 | +printf('ReversedMap benchmarking run on '.date('r').PHP_EOL.PHP_EOL); |
|
| 24 | +printf('%25s %10s %10s %10s'.PHP_EOL, 'Operation', 'n', 'seconds', 'μs/(n log(n))'); |
|
| 25 | +printf('-------------------------------------------------------------'.PHP_EOL); |
|
| 26 | 26 | |
| 27 | 27 | $tree = TreeMap::create(); |
| 28 | 28 | $reversed = ReversedMap::create($tree); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $end = microtime(true); |
| 45 | 45 | |
| 46 | 46 | printf( |
| 47 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 47 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 48 | 48 | 'Search all elements', |
| 49 | 49 | $count, |
| 50 | 50 | $end - $start, |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $end = microtime(true); |
| 71 | 71 | |
| 72 | 72 | printf( |
| 73 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 73 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 74 | 74 | 'Loop on all elements', |
| 75 | 75 | $count, |
| 76 | 76 | $end - $start, |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $end = microtime(true); |
| 95 | 95 | |
| 96 | 96 | printf( |
| 97 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 97 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 98 | 98 | 'Count all elements', |
| 99 | 99 | $count, |
| 100 | 100 | $end - $start, |
@@ -14,15 +14,15 @@ discard block |
||
| 14 | 14 | * This file is part of the php-sorted-collections package https://github.com/chdemko/php-sorted-collections |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -require __DIR__ . '/../vendor/autoload.php'; |
|
| 17 | +require __DIR__.'/../vendor/autoload.php'; |
|
| 18 | 18 | |
| 19 | 19 | use chdemko\SortedCollection\TreeMap; |
| 20 | 20 | use chdemko\SortedCollection\SubMap; |
| 21 | 21 | |
| 22 | 22 | date_default_timezone_set('UTC'); |
| 23 | -printf('SubMap benchmarking run on ' . date('r') . PHP_EOL . PHP_EOL); |
|
| 24 | -printf('%25s %10s %10s %10s' . PHP_EOL, 'Operation', 'n', 'seconds', 'μs/(n log(n))'); |
|
| 25 | -printf('-------------------------------------------------------------' . PHP_EOL); |
|
| 23 | +printf('SubMap benchmarking run on '.date('r').PHP_EOL.PHP_EOL); |
|
| 24 | +printf('%25s %10s %10s %10s'.PHP_EOL, 'Operation', 'n', 'seconds', 'μs/(n log(n))'); |
|
| 25 | +printf('-------------------------------------------------------------'.PHP_EOL); |
|
| 26 | 26 | |
| 27 | 27 | $tree = TreeMap::create(); |
| 28 | 28 | $sub = SubMap::create($tree, null, null); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $end = microtime(true); |
| 49 | 49 | |
| 50 | 50 | printf( |
| 51 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 51 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 52 | 52 | 'Search all elements', |
| 53 | 53 | $count / 2, |
| 54 | 54 | $end - $start, |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $end = microtime(true); |
| 79 | 79 | |
| 80 | 80 | printf( |
| 81 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 81 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 82 | 82 | 'Loop on all elements', |
| 83 | 83 | $count / 2, |
| 84 | 84 | $end - $start, |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $end = microtime(true); |
| 107 | 107 | |
| 108 | 108 | printf( |
| 109 | - '%25s %10d %10.2f %10.2f' . PHP_EOL, |
|
| 109 | + '%25s %10d %10.2f %10.2f'.PHP_EOL, |
|
| 110 | 110 | 'Count all elements', |
| 111 | 111 | $count / 2, |
| 112 | 112 | $end - $start, |