UNPKG

extra-sorted-array

Version:

A sorted array is a collection of values, arranged in an order.

185 lines (181 loc) โ€ข 9.45 kB
import { CompareFunction, MapFunction } from 'extra-array'; export { CombineFunction, CompareFunction, EndFunction, Entries, IEntries, ILists, Lists, MapFunction, ProcessFunction, ReadFunction, ReduceFunction, TestFunction, get as at, last as back, chunk, clear$, shallowClone as clone, compare, count, countEach, cut, cutAt, cutAtRight, cutRight, deepClone, drop, dropRight, dropWhile, dropWhileRight, entries, every, filter, filter$, filterAt, find, search as findIndex, searchRight as findLastIndex, findRight, head as first, forEach, sort as from, sort as fromArray, fromRange, head as front, get, getAll, getPath, group, partitionEach as groupToMap, hasInfix, hasPath, hasPermutation, hasPrefix, hasSubsequence, hasSuffix, head, ientries, iinfixes, ikeys, index, indexRange, infixes, init, iprefixes, isSorted as is, isEmpty, isEqual, isubsequences, isuffixes, ivalues, join, keys, last, take as left, length, middle, partition, partitionEach, prefixes, randomInfix, randomPrefix, randomSubsequence, randomSuffix, randomValue, reduce, reduceRight, reject, reject$, rejectAt, remove, remove$, removePath$, takeRight as right, scanUntil, scanUntilRight, scanWhile, scanWhileRight, search, searchAdjacentDuplicateValue as searchAdjacentDuplicate, searchAdjacentDuplicateValue, searchAll, searchInfix, searchInfixAll, searchInfixRight, searchMismatchedValue as searchMismatch, searchMismatchedValue, searchRight, searchSubsequence, shallowClone, length as size, slice, slice$, some, split, splitAt, subsequences, suffixes, tail, take, takeRight, takeWhile, takeWhileRight, values } from 'extra-array'; /** * Check if sorted array has a value using binary search. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/includes) * @param x a sorted array * @param v search value * @param i begin index [0] * @returns true if value is found */ declare function includes<T>(x: T[], v: T, i?: number): boolean; /** * Check if sorted array has a value using binary search. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/hasValue) * @param x a sorted array * @param v search value * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns true if value is found */ declare function hasValue<T, U = T>(x: T[], v: T, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): boolean; /** * Find first index of value using binary search. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/indexOf) * @param x a sorted array * @param v search value * @param i begin index [0] * @returns index of value, or -1 */ declare function indexOf<T>(x: T[], v: T, i?: number): number; /** * Find last index of value using binary search. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/lastIndexOf) * @param x a sorted array * @param v search value * @param i begin index [|x|-1] * @returns last index of value, or -1 */ declare function lastIndexOf<T>(x: T[], v: T, i?: number): number; /** * Find first index of value using binary search. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/searchValue) * @param x a sorted array * @param v search value * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns first index of value, or ~(index of closest value) */ declare function searchValue<T, U = T>(x: T[], v: T, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): number; /** * Find last index of a value using binary search. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/searchValueRight) * @param x a sorted array * @param v search value * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns last index of value, or ~(index of closest value) */ declare function searchValueRight<T, U = T>(x: T[], v: T, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): number; /** * Find any index of a value using binary search. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/searchValueAny) * @param x a sorted array * @param v search value * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns index of value, or ~(index of closest value) */ declare function searchValueAny<T, U = T>(x: T[], v: T, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): number; /** * Find index of closest value using binary search. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/searchClosestValue) * @param x a sorted array * @param v search value * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns index of closest value */ declare function searchClosestValue<T, U = T>(x: T[], v: T, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): number; /** * Merge values from two sorted arrays. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/merge) * @param x an array * @param y another array * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns x & y | vแตข โ‰ค vแตขโ‚Šโ‚ โˆ€ i โˆˆ x & y */ declare function merge<T, U = T>(x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): T[]; /** * Merge ranges of values from two sorted arrays. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/rangedMerge) * @param x an array * @param i begin index in x * @param I end index in x (exclusive) * @param y another array * @param j begin index in y * @param J end index in y (exclusive) * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns x[i:I] & y[j:J] | vแตข โ‰ค vแตขโ‚Šโ‚ โˆ€ i โˆˆ x[i:I] & y[j:J] */ declare function rangedMerge<T, U = T>(x: T[], i: number, I: number, y: T[], j: number, J: number, fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): T[]; /** * Merge values from sorted arrays. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/mergeAll) * @param xs arrays * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns xโ‚€ & xโ‚ & ... | vแตข โ‰ค vแตขโ‚Šโ‚ โˆ€ i โˆˆ xโ‚€ & xโ‚ & ... */ declare function mergeAll<T, U = T>(xs: T[][], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): T[]; /** * Examine if there are no duplicate values. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/isUnique) * @param x a sorted array * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns โˆ€ vแตข, vโฑผ โˆˆ x, is vแตข โ‰  vโฑผ? */ declare function isUnique<T, U = T>(x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): boolean; /** * Examine if arrays have no value in common. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/isDisjoint) * @param x a sorted array * @param y another sorted array * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns x โˆฉ y = ฮฆ? */ declare function isDisjoint<T, U = T>(x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): boolean; /** * Remove duplicate values. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/unique) * @param x a sorted array * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns vโ‚€, vโ‚, ... | vแตข โˆˆ x; vแตข โ‰  vโฑผ โˆ€ i, j */ declare function unique<T, U = T>(x: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): T[]; /** * Obtain values present in any sorted array. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/union) * @param x a sorted array * @param y another sorted array * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns x โˆช y = \{v | v โˆˆ x or v โˆˆ y\} */ declare function union<T, U = T>(x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): T[]; /** * Obtain values present in both sorted arrays. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/intersection) * @param x a sorted array * @param y another sorted array * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns x โˆฉ y = \{v | v โˆˆ x, v โˆˆ y\} */ declare function intersection<T, U = T>(x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): T[]; /** * Obtain values not present in another sorted array. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/difference) * @param x a sorted array * @param y another sorted array * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns x - y = \{v | v โˆˆ x, v โˆ‰ y\} */ declare function difference<T, U = T>(x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): T[]; /** * Obtain values present in either sorted array but not both. * [๐Ÿ“˜](https://github.com/nodef/extra-sorted-array/wiki/symmetricDifference) * @param x a sorted array * @param y another sorted array * @param fc compare function (a, b) * @param fm map function (v, i, x) * @returns x-y โˆช y-x */ declare function symmetricDifference<T, U = T>(x: T[], y: T[], fc?: CompareFunction<T | U> | null, fm?: MapFunction<T, T | U> | null): T[]; export { mergeAll as concat, difference, hasValue, includes, indexOf, intersection, isDisjoint, isUnique, lastIndexOf, merge, mergeAll, rangedMerge, searchClosestValue, searchValue, searchValueAny, searchValueRight, symmetricDifference, union, unique };