LoopedArray<T>
Guide: /guide/data-structures/looped-array
Generic Types
T
- type of collection elements
Implements interfaces
IArrayFacade
ILinearStorage
ILinearStorageRA
Methods
constructor(capacity: number): IArrayFacade<T>
Creates empty instance
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
capacity | number | + | - | Max capacity of array (> 0) |
ValueOutOfRangeException
when given capacity is out of range
Throws: peek(): T
Returns value from top of array
pop(): T
Removes item from array end (head element) and returns its value
CollectionIsEmptyException
when array is empty
Throws: push(value: T): void
Add value to top of array
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - |
has(value: T): boolean
Check is array has given value
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - |
peekFromStart(): T
Get first element of array
peekByIndex(index: number): T
Get element by given index from array start
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
index | number | + | - | 0 <= index <= array.length - 1 |
unshift(value: T): void
Add new node into array start
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - |
pushFromIndex(value: T, fromIndex: number): void
Add new node into array by index
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
value | T | + | - | |
fromIndex | number | + | - | 0 <= index <= array.length - 1 |
shift(): T
Remove node from array start and get its value
CollectionIsEmptyException
when array is empty
Throws: deleteFromIndex(fromIndex: number): T
Remove node from array by index
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
fromIndex | number | + | - | 0 <= index <= array.length - 1 |
pushFromArray(elements: Array<T>): void
Add elements from array collection in order from start
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
elements | Array<T> | + | - |
getAsArray(): Array<T>
Convert linked array into array collection in order from start
Params:
Name | Type | Required | Default | Description |
---|---|---|---|---|
elements | Array<T> | + | - |
clear(): void
Remove all elements from array
isEmpty(): boolean
Check is array has any value, returns true if array is empty
isFull(): boolean
Check is array length exceed max capacity
length(): number
Get array size