Class: SortedArray<T>
Defined in: src/sdk/utils/datastructures/SortedArray.ts:4
A sorted array.
Type Parameters
Type Parameter |
---|
T |
Constructors
Constructor
new SortedArray<
T
>(comparatorFunc
,equalityFunc
):SortedArray
<T
>
Defined in: src/sdk/utils/datastructures/SortedArray.ts:30
Constructor.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
comparatorFunc | (a , b ) => 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 , b ) => 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
>
Accessors
array
Get Signature
get array(): readonly
T
[]
Defined in: src/sdk/utils/datastructures/SortedArray.ts:10
A read-only version of the array object backing this sorted array.
Returns
readonly T
[]
length
Get Signature
get length():
number
Defined in: src/sdk/utils/datastructures/SortedArray.ts:18
The number of elements in this array.
Returns
number
The number of elements in the array.
Methods
[iterator]()
[iterator]():
IterableIterator
<T
>
Defined in: src/sdk/utils/datastructures/SortedArray.ts:338
Returns
IterableIterator
<T
>
Inherit Doc
clear()
clear():
void
Defined in: src/sdk/utils/datastructures/SortedArray.ts:325
Removes all elements from this array.
Returns
void
first()
first():
T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:118
Gets the first element in this array.
Returns
T
The first element in this array.
Throws
RangeError if this array is empty.
get()
get(
index
):T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:96
Gets the element at a specified index.
Parameters
Parameter | Type | Description |
---|---|---|
index | number | An index. |
Returns
T
The element at the specified index.
Throws
RangeError if index is out of bounds.
has()
has(
element
):boolean
Defined in: src/sdk/utils/datastructures/SortedArray.ts:161
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
Parameter | Type | Description |
---|---|---|
element | T | The element to check. |
Returns
boolean
Whether this array contains the element.
indexOf()
indexOf(
element
):number
Defined in: src/sdk/utils/datastructures/SortedArray.ts:293
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
Parameter | 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.
insert()
insert(
element
):number
Defined in: src/sdk/utils/datastructures/SortedArray.ts:173
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
Parameter | Type | Description |
---|---|---|
element | T | The element to insert. |
Returns
number
The index at which the element was placed.
insertAll()
insertAll(
elements
):number
Defined in: src/sdk/utils/datastructures/SortedArray.ts:189
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
Parameter | Type | Description |
---|---|---|
elements | Iterable <T > | An iterable of elements to insert. |
Returns
number
The number of elements inserted.
last()
last():
T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:139
Gets the last element in this array.
Returns
T
The last element in this array.
Throws
RangeError if this array is empty.
match()
match(
query
):undefined
|T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:304
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
Parameter | 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.
matchIndex()
matchIndex(
query
):number
Defined in: src/sdk/utils/datastructures/SortedArray.ts:318
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
Parameter | 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.
peek()
peek(
index
):undefined
|T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:109
Gets the element at a specified index, if it exists.
Parameters
Parameter | Type | Description |
---|---|---|
index | number | An index. |
Returns
undefined
| T
The element at the specified index, or undefined if the index is out of bounds.
peekFirst()
peekFirst():
undefined
|T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:130
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.
peekLast()
peekLast():
undefined
|T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:151
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.
pop()
pop():
undefined
|T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:268
Removes the last element from this array and returns it.
Returns
undefined
| T
The removed element, or undefined
if the array was empty.
remove()
remove(
element
):number
Defined in: src/sdk/utils/datastructures/SortedArray.ts:217
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
Parameter | Type | Description |
---|---|---|
element | T | The element to remove. |
Returns
number
The (former) index of the removed element, or -1 if no element was removed.
removeAll()
removeAll(
elements
):number
Defined in: src/sdk/utils/datastructures/SortedArray.ts:232
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
Parameter | Type | Description |
---|---|---|
elements | Iterable <T > | An iterable of elements to remove. |
Returns
number
The number of elements removed.
removeAt()
removeAt(
index
):undefined
|T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:256
Removes an element at a specific index from this array and returns it.
Parameters
Parameter | Type | Description |
---|---|---|
index | number | The index of the element to remove. |
Returns
undefined
| T
The removed element, or undefined
if no element was removed.
resort()
resort():
void
Defined in: src/sdk/utils/datastructures/SortedArray.ts:283
Re-sorts this array using its sorting function.
Returns
void
shift()
shift():
undefined
|T
Defined in: src/sdk/utils/datastructures/SortedArray.ts:276
Removes the first element from this array and returns it.
Returns
undefined
| T
The removed element, or undefined
if the array was empty.
values()
values():
IterableIterator
<T
>
Defined in: src/sdk/utils/datastructures/SortedArray.ts:333
Gets an IterableIterator over all elements in this array.
Returns
IterableIterator
<T
>
An IterableIterator over all elements in this array.