Class: SortedArray<T>
A sorted array.
Type parameters
Name |
---|
T |
Constructors
constructor
• new SortedArray<T
>(comparatorFunc
, equalityFunc?
): SortedArray
<T
>
Constructor.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
comparatorFunc | (a : T , b : T ) => number | undefined | A function which defines the relative sorting priority of two elements. The function should return 0 if its arguments are to be sorted identically, a negative number if the first argument is to be sorted before the second argument, and a positive number if the first argument is to be sorted after the second argument. |
equalityFunc | (a : T , b : T ) => boolean | SortedArray.DEFAULT_EQUALITY_FUNC | A function which checks if two elements are equal. Defaults to the strict equality comparison (=== ) if not defined. |
Returns
SortedArray
<T
>
Defined in
src/sdk/utils/datastructures/SortedArray.ts:30
Accessors
array
• get
array(): readonly T
[]
A read-only version of the array object backing this sorted array.
Returns
readonly T
[]
Defined in
src/sdk/utils/datastructures/SortedArray.ts:10
length
• get
length(): number
The number of elements in this array.
Returns
number
The number of elements in the array.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:18
Methods
[iterator]
▸ [iterator](): IterableIterator
<T
>
Returns
IterableIterator
<T
>
Inherit Doc
Defined in
src/sdk/utils/datastructures/SortedArray.ts:338
clear
▸ clear(): void
Removes all elements from this array.
Returns
void
Defined in
src/sdk/utils/datastructures/SortedArray.ts:325
first
▸ first(): T
Gets the first element in this array.
Returns
T
The first element in this array.
Throws
RangeError if this array is empty.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:118
get
▸ get(index
): T
Gets the element at a specified index.
Parameters
Name | Type | Description |
---|---|---|
index | number | An index. |
Returns
T
The element at the specified index.
Throws
RangeError if index is out of bounds.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:96
has
▸ has(element
): boolean
Checks whether this array contains an element. Returns true if and only if there is at least one element in this array which is equal to the specified element according to this array's equality function.
Parameters
Name | Type | Description |
---|---|---|
element | T | The element to check. |
Returns
boolean
Whether this array contains the element.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:161
indexOf
▸ indexOf(element
): number
Finds the index of the first occurrence of an element in this array. This array is searched for the first element which is equal to the specified element according to this array's equality function, and its index is returned.
Parameters
Name | Type | Description |
---|---|---|
element | T | The element for which to search. |
Returns
number
The index of the first occurrence of the specified element, or -1 if no such element was found.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:293
insert
▸ insert(element
): number
Inserts an element into this array. The element will be inserted at the greatest index such that it is located before all the existing elements in the array sorted after it according to this array's sorting function. All existing elements located at indexes greater than or equal to the index at which the element was inserted are shifted to the right.
Parameters
Name | Type | Description |
---|---|---|
element | T | The element to insert. |
Returns
number
The index at which the element was placed.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:173
insertAll
▸ insertAll(elements
): number
Inserts all elements in an Iterable into this array. Each element is inserted according to the same behavior used
by the insert()
method. If an element appears more than once in the iterable, one instance of that element will
be inserted into this array for each time the element appears in the iterable.
Parameters
Name | Type | Description |
---|---|---|
elements | Iterable <T > | An iterable of elements to insert. |
Returns
number
The number of elements inserted.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:189
last
▸ last(): T
Gets the last element in this array.
Returns
T
The last element in this array.
Throws
RangeError if this array is empty.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:139
match
▸ match(query
): undefined
| T
Searches this array for the first element whose sorting priority is equal to a query element. If no such element is found, then undefined is returned instead.
Parameters
Name | Type | Description |
---|---|---|
query | T | The query element. |
Returns
undefined
| T
The first element in the array with the same sorting priority as the query, or undefined if no such element exists.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:304
matchIndex
▸ matchIndex(query
): number
Searches this array for the index of the first element whose sorting priority is equal to a query element. If no
such element is found, then -(index + 1)
is returned instead, where index
is the index at which the query
element would be found if it were contained in the array.
Parameters
Name | Type | Description |
---|---|---|
query | T | The query element. |
Returns
number
The index of the first element in this array with the same sorting priority as the query, or
-(index + 1)
if no such element exists, where index
is the index at which the query element would be found if
it were contained in the array.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:318
peek
▸ peek(index
): undefined
| T
Gets the element at a specified index, if it exists.
Parameters
Name | Type | Description |
---|---|---|
index | number | An index. |
Returns
undefined
| T
The element at the specified index, or undefined if the index is out of bounds.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:109
peekFirst
▸ peekFirst(): undefined
| T
Gets the first element in this array, if it exists.
Returns
undefined
| T
The first element in this array, or undefined if this array is empty.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:130
peekLast
▸ peekLast(): undefined
| T
Gets the last element in this array, if it exists.
Returns
undefined
| T
The last element in this array, or undefined if this array is empty.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:151
pop
▸ pop(): undefined
| T
Removes the last element from this array and returns it.
Returns
undefined
| T
The removed element, or undefined
if the array was empty.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:268
remove
▸ remove(element
): number
Removes the first occurrence of an element from this array. This array is searched for the first element which is equal to the specified element according to this array's equality function, the matching element is removed, and all elements after it are shifted to the left.
Parameters
Name | Type | Description |
---|---|---|
element | T | The element to remove. |
Returns
number
The (former) index of the removed element, or -1 if no element was removed.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:217
removeAll
▸ removeAll(elements
): number
Removes all elements in an Iterable from this array. Each element is removed according to the behavior used by the
remove()
method. If an element appears more than once in the iterable, one instance of that element will be
removed from this array for each time the element appears in the iterable.
Parameters
Name | Type | Description |
---|---|---|
elements | Iterable <T > | An iterable of elements to remove. |
Returns
number
The number of elements removed.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:232
removeAt
▸ removeAt(index
): undefined
| T
Removes an element at a specific index from this array and returns it.
Parameters
Name | Type | Description |
---|---|---|
index | number | The index of the element to remove. |
Returns
undefined
| T
The removed element, or undefined
if no element was removed.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:256
resort
▸ resort(): void
Re-sorts this array using its sorting function.
Returns
void
Defined in
src/sdk/utils/datastructures/SortedArray.ts:283
shift
▸ shift(): undefined
| T
Removes the first element from this array and returns it.
Returns
undefined
| T
The removed element, or undefined
if the array was empty.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:276
values
▸ values(): IterableIterator
<T
>
Gets an IterableIterator over all elements in this array.
Returns
IterableIterator
<T
>
An IterableIterator over all elements in this array.
Defined in
src/sdk/utils/datastructures/SortedArray.ts:333