@itwin/core-bentley
Version:
Bentley JavaScript core components
68 lines • 3.52 kB
TypeScript
/** @packageDocumentation
* @module Utils
*/
/**
* 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](https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings), 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
* @see Dictionary
* @see IndexMap
* @see PriorityQueue
* @public
*/
export type OrderedComparator<T, U = T> = (lhs: T, rhs: U) => number;
/**
* An [[OrderedComparator]] for numbers that treats two numbers as equal if the absolute value of their difference is less than a specified tolerance.
* @public
*/
export declare function compareWithTolerance(a: number, b: number, tolerance?: number): number;
/** @public */
export declare function compareNumbers(a: number, b: number): number;
/** @public */
export declare function compareBooleans(a: boolean, b: boolean): number;
/** @public */
export declare function compareStrings(a: string, b: string): number;
/** @public */
export declare function comparePossiblyUndefined<T>(compareDefined: (lhs: T, rhs: T) => number, lhs?: T, rhs?: T): number;
/** @public */
export declare function compareStringsOrUndefined(lhs?: string, rhs?: string): number;
/** @public */
export declare function compareNumbersOrUndefined(lhs?: number, rhs?: number): number;
/** @public */
export declare function compareBooleansOrUndefined(lhs?: boolean, rhs?: boolean): number;
/** Compare two possibly-undefined values for equality. If both are undefined, the comparison is performed by the supplied `areEqual` function.
* @public
*/
export declare function areEqualPossiblyUndefined<T, U>(t: T | undefined, u: U | undefined, areEqual: (t: T, u: U) => boolean): boolean;
/**
* Compare two simples types (number, string, boolean)
* This essentially wraps the existing type-specific comparison functions
* @beta */
export declare function compareSimpleTypes(lhs: number | string | boolean, rhs: number | string | boolean): number;
/**
* An array of simple types (number, string, boolean)
* @beta
*/
export type SimpleTypesArray = number[] | string[] | boolean[];
/**
* Compare two arrays of simple types (number, string, boolean)
* @beta
*/
export declare function compareSimpleArrays(lhs?: SimpleTypesArray, rhs?: SimpleTypesArray): number;
/** Compare two arrays of the same type `T` using the specified `compare` function to compare each pair of array elements.
* @returns 0 if the arrays have the same length and `compare` returns 0 for each pair of elements, or a non-zero value if the arrays differ in length or contents.
* @public
*/
export declare function compareArrays<T>(lhs: ReadonlyArray<T>, rhs: ReadonlyArray<T>, compare: (a: T, b: T) => number): number;
//# sourceMappingURL=Compare.d.ts.map