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 doescompare(y, x)
(i.e.,x == y
impliesy == x
). - If
compare(x, y)
returns non-zero, thencompare(y, x)
returns a value with an opposite sign (i.e.,x < y
impliesy > x
). - If
compare(x, y)
andcompare(y, z)
return non-zero values with the same sign, thencompare(x, z)
returns a value with the same sign (i.e.,x < y < z
impliesx < z
).
@see - SortedArray
- Dictionary
- IndexMap
- PriorityQueue
Defined in
- core/bentley/src/Compare.ts Line 29
Last Updated: 21 November, 2024
Found something wrong, missing, or unclear on this page?Raise an issue in our repo.