| @@ 494-506 (lines=13) @@ | ||
| 491 | * |
|
| 492 | * @param callable|null $comparator Accepts two values to be compared. |
|
| 493 | */ |
|
| 494 | public function sort(callable $comparator = null) |
|
| 495 | { |
|
| 496 | if ($comparator) { |
|
| 497 | usort($this->internal, function($a, $b) use ($comparator) { |
|
| 498 | return $comparator($a->value, $b->value); |
|
| 499 | }); |
|
| 500 | ||
| 501 | } else { |
|
| 502 | usort($this->internal, function($a, $b) { |
|
| 503 | return $a->value <=> $b->value; |
|
| 504 | }); |
|
| 505 | } |
|
| 506 | } |
|
| 507 | ||
| 508 | /** |
|
| 509 | * Returns a sorted copy of the map, based on an optional callable |
|
| @@ 541-553 (lines=13) @@ | ||
| 538 | * |
|
| 539 | * @param callable|null $comparator Accepts two keys to be compared. |
|
| 540 | */ |
|
| 541 | public function ksort(callable $comparator = null) |
|
| 542 | { |
|
| 543 | if ($comparator) { |
|
| 544 | usort($this->internal, function($a, $b) use ($comparator) { |
|
| 545 | return $comparator($a->key, $b->key); |
|
| 546 | }); |
|
| 547 | ||
| 548 | } else { |
|
| 549 | usort($this->internal, function($a, $b) { |
|
| 550 | return $a->key <=> $b->key; |
|
| 551 | }); |
|
| 552 | } |
|
| 553 | } |
|
| 554 | ||
| 555 | /** |
|
| 556 | * Returns a sorted copy of the map, based on an optional callable |
|