Interface Comparator
A strategy for sorting values.
A comparison function, which imposes a total ordering on some collection of objects. Comparators can be passed to a sort method of a collection to allow precise control over its sort order. It can also be used to control the order of certain data structures, such as sorted sets or sorted maps.
The ordering imposed by a Ordering $c
on a set of elements S
is
said to be consistent with an PhpCommon\Comparison\Equivalence
$e
if and only if
$c->compare($a, $b) === 0
has the same boolean value as
$e->equivalent($a, $b)
for every $a
and $b
in S
.
It is strongly recommended, though not required, that natural orderings be consistent with Equatable::equals(). This is so because in certain cases these methods can be used together in a complementary way to achieve specific results. For example, some structures, such as sets and maps, may use both Equatable::equals() and Ordering::compare() methods as part of the strategy to determine where to store or retrieve data. In the way, such inconsistency may lead to unwanted results.
It is inspired by the Comparator interface, from Java API.
Author: Marcos Passos marcos@croct.com
Link: Java Comparator interface
Located at Comparator.php
public
integer
|