Skip to main content
Module

x/structurae/index.ts>SortedArray

Data structures for high-performance JavaScript applications.
Latest
class SortedArray
extends Array<ItemType>
import { SortedArray } from "https://deno.land/x/structurae@4.0.1/index.ts";

Extends Array to handle sorted data.

Properties

unique: boolean

Methods

concat(...arrays: Array<Array<ItemType>>): SortedArray<ItemType>

Returns a merger of the array with one or more provided sorted arrays.

includes(element: ItemType): boolean

Uses binary search to quickly check if the element is the array.

indexOf(element: ItemType): number

Looks for the index of a given element in the array or -1

isSorted(): boolean

Checks if the array is sorted.

isUnique(): boolean

Checks if the array has duplicating elements.

push(...elements: Array<ItemType>): number

Adds provided elements to the array preserving the sorted order of the array.

Returns a range of elements of the array that are greater or equal to the provided starting element and less or equal to the provided ending element.

rank(element: ItemType): number

Returns the rank of an element in the array.

set(arr: Array<ItemType>): this

Implements in-place replacement of the array elements.

sort(compareFunction?: Comparator<ItemType>): this

Sorts the array with a provided compare function.

splice(
start: number,
deleteCount: number,
...elements: Array<ItemType>,
): SortedArray<ItemType>

Changes the array by removing existing elements and adding new ones.

Removes duplicating elements from the array.

unshift(...elements: Array<ItemType>)

Adds provided elements to the array preserving the sorted order of the array.

Static Methods

compare<T>(a: T, b: T): -1 | 0 | 1

The default comparator.

from<T>(iterable: Iterable<T> | ArrayLike<T>): SortedArray<T>

Creates a new SortedArray from a given array-like object.

getDifference<T, U extends IndexedCollection<T>>(
a: U,
b: U,
symmetric?,
comparator?: Comparator<T>,
container?: U,
): container

Returns the difference of two sorted arrays, i.e. elements present in the first array but not in the second array. If symmetric=true finds the symmetric difference of two arrays, that is, the elements that are absent in one or another array.

getDifferenceScore<T, U extends IndexedCollection<T>>(
a: U,
b: U,
symmetric?,
comparator?,
): number

Returns the amount of differing elements in the first array.

getIndex<T, U extends IndexedCollection<T>>(
arr: U,
target: T,
comparator?: Comparator<T>,
rank?,
start?,
end?,
): number

Uses binary search to find the index of an element inside a sorted array.

getIntersection<T, U extends IndexedCollection<T>>(
a: U,
b: U,
comparator?: Comparator<T>,
container?: U,
): U

Returns the intersection of two sorted arrays.

getIntersectionScore<T, U extends IndexedCollection<T>>(
a: U,
b: U,
comparator?: Comparator<T>,
): number

Returns the amount of common elements in two sorted arrays.

getRange<T, U extends IndexedCollection<T>>(
arr: U,
start?: T,
end?: T,
comparator?: Comparator<T>,
subarray?: boolean,
): U

Returns a range of elements of a sorted array from the start through the end inclusively.

getUnion<T, U extends IndexedCollection<T>>(
unique?,
comparator?: Comparator<T>,
container?: U,
): U

Returns the union of two sorted arrays as a sorted array.

getUnique<T, U extends IndexedCollection<T>>(
comparator?: Comparator<T>,
container?: U,
): container

Returns an array of unique elements from a sorted array.

isSorted<T, U extends IndexedCollection<T>>(arr: U, comparator?: Comparator<T>): boolean

Checks whether an array is sorted according to a provided comparator.

isUnique<T, U extends IndexedCollection<T>>(arr: U, comparator?: Comparator<T>)

Checks whether an array has any duplicating elements.

of<U>(...elements: Array<U>): SortedArray<U>

Creates a new SortedArray instance with a variable number of arguments, regardless of number or type of the arguments