/// /// /// import type { CompareFunction } from "../types"; /** * A class to create sorted arrays. Must contain objects comparable to * one another (that can use the `<` and `==` operators). Numbers and * strings support these operators by default. * * @example * const array0 = new SortedArray([3, 1, 2]); // will sort * const array1 = new SortedArray(); * * @author Validark */ export declare class SortedArray { readonly array: Array; comparison?: CompareFunction; /** * Instantiates and returns a new SortedArray, with optional parameters. * @param baseArray An array of data which will be sorted upon instantiation. If this is omitted, an empty array is used. * @param comparison An optional comparison function which is used to customize the element sorting, which will be given two elements `a` and `b` from the array as parameters. The function should return a boolean value specifying whether the first argument should be before the second argument in the sequence. If no comparison function is passed, the Lua-default `a < b` sorting is used. */ constructor(baseArray?: Array, comparison?: CompareFunction); static readonly instanceof: (value: unknown) => value is SortedArray; map(callback: (value: T, index: number, array: ReadonlyArray) => U, comparison?: CompareFunction): SortedArray; /** * A combination function of `Array.filter` and `Array.map`. If * the predicate function returns nil, the value will not be * included in the new list. Any other result will add the result * value to the new list. * * @example * const array = new SortedArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).mapFiltered((value) => { * return value % 2 === 0 || value % 3 === 0 ? undefined : value; * }); * print(array); // [2, 4, 8, 10]; * * @param callback * @param comparison * @returns */ mapFiltered(callback: (value: T, index: number, array: ReadonlyArray) => U, comparison?: CompareFunction): SortedArray>; /** * Inserts an element in the proper place which would preserve the array's sorted order. * Returns the index the element was inserted. * * @param value * @returns */ insert(value: T): number; /** * Finds an Element in a SortedArray and returns its position (or nil if non-existent). * * @param value The element to find or something that will be matched by the `eq` function. * @param eq An optional function which checks for equality between the passed-in element and the other elements in the SortedArray. * @param lt An optional less-than comparison function, which falls back on the comparison passed in from `new SortedArray`. * @param low The lowest index to search. Defaults to 0. * @param high The high index to search. Defaults to the length of the SortedArray - 1. * @returns */ find(value: T, eq?: CompareFunction, lt?: CompareFunction, low?: number, high?: number): number | undefined; indexOf(value: T, eq?: CompareFunction, lt?: CompareFunction, low?: number, high?: number): number | undefined; /** * Makes a shallow copy of the SortedArray. * @returns */ copy(): T[]; /** * Makes a shallow copy of the SortedArray and returns a new SortedArray. * @returns */ clone(): SortedArray; /** * Searches the array via {@linkcode find}. If found, it removes the * value and returns the value, otherwise returns undefined. Only * removes a single occurrence. * * @param signature The value you want to remove. * @param eq An optional function which checks for equality between the passed-in element and the other elements in the SortedArray. * @param lt An optional less-than comparison function, which falls back on the comparison passed in from `SortedArray.new`. * @returns */ removeElement(signature: T, eq?: CompareFunction, lt?: CompareFunction): T | undefined; /** * Calls `Array.remove` on the SortedArray. * @param index * @returns */ removeIndex(index: number): T | undefined; unorderedRemoveIndex(index: number): T | undefined; pop(): T | undefined; shift(): T | undefined; /** * Does `this.array.sort(this.comparison)` and returns the SortedArray. * @returns */ sort(): this; getIntersection(other: SortedArray, eq?: CompareFunction, lt?: CompareFunction): SortedArray; size(): number; isEmpty(): boolean; get(index: number): T; }