OrderedComparator<T, U> Type

OrderedComparator = (lhs: T, rhs: U) => number

A function that returns a numerical value indicating how two objects are ordered in relation to one another. Such functions are used by various collection classes throughout the library. Given values lhs and rhs, the function returns:

  • Zero if lhs == rhs
  • A negative number if lhs < rhs
  • A positive number if lhs > rhs

An OrderedComparator must implement strict weak ordering, which can be summarized by the following rules:

  • compare(x, x) returns zero.
  • If compare(x, y) returns zero, then so does compare(y, x) (i.e., x == y implies y == x).
  • If compare(x, y) returns non-zero, then compare(y, x) returns a value with an opposite sign (i.e., x < y implies y > x).
  • If compare(x, y) and compare(y, z) return non-zero values with the same sign, then compare(x, z) returns a value with the same sign (i.e., x < y < z implies x < z).

@see - SortedArray

  • Dictionary
  • IndexMap
  • PriorityQueue

Defined in

Last Updated: 14 November, 2024