import { CancellationToken } from '../../base/common/cancellation'; import { ISplice } from '../../base/common/sequence'; /** * Returns the last element of an array. * @param array The array. * @param n Which element from the end (default is zero). */ export declare function tail(array: ArrayLike, n?: number): T; export declare function tail2(arr: T[]): [T[], T]; export declare function equals(one: ReadonlyArray | undefined, other: ReadonlyArray | undefined, itemEquals?: (a: T, b: T) => boolean): boolean; export declare function binarySearch(array: ReadonlyArray, key: T, comparator: (op1: T, op2: T) => number): number; /** * Takes a sorted array and a function p. The array is sorted in such a way that all elements where p(x) is false * are located before all elements where p(x) is true. * @returns the least x for which p(x) is true or array.length if no element fullfills the given function. */ export declare function findFirstInSorted(array: ReadonlyArray, p: (x: T) => boolean): number; declare type Compare = (a: T, b: T) => number; export declare function quickSelect(nth: number, data: T[], compare: Compare): T; export declare function groupBy(data: ReadonlyArray, compare: (a: T, b: T) => number): T[][]; /** * Diffs two *sorted* arrays and computes the splices which apply the diff. */ export declare function sortedDiff(before: ReadonlyArray, after: ReadonlyArray, compare: (a: T, b: T) => number): ISplice[]; /** * Takes two *sorted* arrays and computes their delta (removed, added elements). * Finishes in `Math.min(before.length, after.length)` steps. */ export declare function delta(before: ReadonlyArray, after: ReadonlyArray, compare: (a: T, b: T) => number): { removed: T[]; added: T[]; }; /** * Returns the top N elements from the array. * * Faster than sorting the entire array when the array is a lot larger than N. * * @param array The unsorted array. * @param compare A sort function for the elements. * @param n The number of elements to return. * @return The first n elements from array when sorted with compare. */ export declare function top(array: ReadonlyArray, compare: (a: T, b: T) => number, n: number): T[]; /** * Asynchronous variant of `top()` allowing for splitting up work in batches between which the event loop can run. * * Returns the top N elements from the array. * * Faster than sorting the entire array when the array is a lot larger than N. * * @param array The unsorted array. * @param compare A sort function for the elements. * @param n The number of elements to return. * @param batch The number of elements to examine before yielding to the event loop. * @return The first n elements from array when sorted with compare. */ export declare function topAsync(array: T[], compare: (a: T, b: T) => number, n: number, batch: number, token?: CancellationToken): Promise; /** * @returns New array with all falsy values removed. The original array IS NOT modified. */ export declare function coalesce(array: ReadonlyArray): T[]; /** * Remove all falsy values from `array`. The original array IS modified. */ export declare function coalesceInPlace(array: Array): void; /** * Moves the element in the array for the provided positions. */ export declare function move(array: any[], from: number, to: number): void; /** * @returns false if the provided object is an array and not empty. */ export declare function isFalsyOrEmpty(obj: any): boolean; /** * @returns True if the provided object is an array and has at least one element. */ export declare function isNonEmptyArray(obj: T[] | undefined | null): obj is T[]; export declare function isNonEmptyArray(obj: readonly T[] | undefined | null): obj is readonly T[]; /** * Removes duplicates from the given array. The optional keyFn allows to specify * how elements are checked for equality by returning a unique string for each. */ export declare function distinct(array: ReadonlyArray, keyFn?: (t: T) => string): T[]; export declare function distinctES6(array: ReadonlyArray): T[]; export declare function uniqueFilter(keyFn: (t: T) => string): (t: T) => boolean; export declare function findLast(arr: readonly T[], predicate: (item: T) => boolean): T | undefined; export declare function lastIndex(array: ReadonlyArray, fn: (item: T) => boolean): number; export declare function firstOrDefault(array: ReadonlyArray, notFoundValue: NotFound): T | NotFound; export declare function firstOrDefault(array: ReadonlyArray): T | undefined; export declare function commonPrefixLength(one: ReadonlyArray, other: ReadonlyArray, equals?: (a: T, b: T) => boolean): number; export declare function flatten(arr: T[][]): T[]; export declare function range(to: number): number[]; export declare function range(from: number, to: number): number[]; export declare function index(array: ReadonlyArray, indexer: (t: T) => string): { [key: string]: T; }; export declare function index(array: ReadonlyArray, indexer: (t: T) => string, mapper: (t: T) => R): { [key: string]: R; }; /** * Inserts an element into an array. Returns a function which, when * called, will remove that element from the array. */ export declare function insert(array: T[], element: T): () => void; /** * Removes an element from an array if it can be found. */ export declare function remove(array: T[], element: T): T | undefined; /** * Insert `insertArr` inside `target` at `insertIndex`. * Please don't touch unless you understand https://jsperf.com/inserting-an-array-within-an-array */ export declare function arrayInsert(target: T[], insertIndex: number, insertArr: T[]): T[]; /** * Uses Fisher-Yates shuffle to shuffle the given array */ export declare function shuffle(array: T[], _seed?: number): void; /** * Pushes an element to the start of the array, if found. */ export declare function pushToStart(arr: T[], value: T): void; /** * Pushes an element to the end of the array, if found. */ export declare function pushToEnd(arr: T[], value: T): void; export declare function mapArrayOrNot(items: T | T[], fn: (_: T) => U): U | U[]; export declare function asArray(x: T | T[]): T[]; export declare function asArray(x: T | readonly T[]): readonly T[]; export declare function getRandomElement(arr: T[]): T | undefined; /** * Returns the first mapped value of the array which is not undefined. */ export declare function mapFind(array: Iterable, mapFn: (value: T) => R | undefined): R | undefined; /** * Insert the new items in the array. * @param array The original array. * @param start The zero-based location in the array from which to start inserting elements. * @param newItems The items to be inserted */ export declare function insertInto(array: T[], start: number, newItems: T[]): void; /** * Removes elements from an array and inserts new elements in their place, returning the deleted elements. Alternative to the native Array.splice method, it * can only support limited number of items due to the maximum call stack size limit. * @param array The original array. * @param start The zero-based location in the array from which to start removing elements. * @param deleteCount The number of elements to remove. * @returns An array containing the elements that were deleted. */ export declare function splice(array: T[], start: number, deleteCount: number, newItems: T[]): T[]; /** * Like Math.min with a delegate, and returns the winning index */ export declare function minIndex(array: readonly T[], fn: (value: T) => number): number; /** * Like Math.max with a delegate, and returns the winning index */ export declare function maxIndex(array: readonly T[], fn: (value: T) => number): number; export declare class ArrayQueue { private readonly items; private firstIdx; private lastIdx; /** * Constructs a queue that is backed by the given array. Runtime is O(1). */ constructor(items: T[]); get length(): number; /** * Consumes elements from the beginning of the queue as long as the predicate returns true. * If no elements were consumed, `null` is returned. Has a runtime of O(result.length). */ takeWhile(predicate: (value: T) => boolean): T[] | null; /** * Consumes elements from the end of the queue as long as the predicate returns true. * If no elements were consumed, `null` is returned. * The result has the same order as the underlying array! */ takeFromEndWhile(predicate: (value: T) => boolean): T[] | null; peek(): T | undefined; } export {}; //# sourceMappingURL=arrays.d.ts.map