CircularArray
-
Cmn
class CircularArray<E : Any?>
CircularArray is a generic circular array data structure that provides O(1) random read, O(1) prepend and O(1) append. The CircularArray automatically grows its capacity when number of added items is over its capacity.
Summary
Public constructors |
|
|---|---|
<E : Any?> CircularArray(minCapacity: Int)Creates a circular array with capacity for at least |
Cmn
|
Public functions |
||
|---|---|---|
Unit |
addFirst(element: E)Add an element in front of the |
Cmn
|
Unit |
addLast(element: E)Add an element at end of the CircularArray. |
Cmn
|
Unit |
clear()Remove all elements from the |
Cmn
|
operator E |
Get nth (0 <= n <= size()-1) element of the |
Cmn
|
Boolean |
isEmpty()Return |
Cmn
|
E |
popFirst()Remove first element from front of the |
Cmn
|
E |
popLast()Remove last element from end of the |
Cmn
|
Unit |
removeFromEnd(count: Int)Remove multiple elements from end of the |
Cmn
|
Unit |
removeFromStart(count: Int)Remove multiple elements from front of the |
Cmn
|
Int |
size()Get number of elements in the |
Cmn
|
Public properties |
||
|---|---|---|
E |
Get first element of the |
Cmn
|
E |
Get last element of the |
Cmn
|
Public constructors
CircularArray
<E : Any?> CircularArray(minCapacity: Int = 8)
Creates a circular array with capacity for at least minCapacity elements.
| Parameters | |
|---|---|
minCapacity: Int = 8 |
the minimum capacity, between 1 and 2^30 inclusive |
Public functions
addFirst
fun addFirst(element: E): Unit
Add an element in front of the CircularArray.
| Parameters | |
|---|---|
element: E |
Element to add. |
addLast
fun addLast(element: E): Unit
Add an element at end of the CircularArray.
| Parameters | |
|---|---|
element: E |
Element to add. |
get
operator fun get(index: Int): E
Get nth (0 <= n <= size()-1) element of the CircularArray.
| Parameters | |
|---|---|
index: Int |
The zero based element index in the |
| Returns | |
|---|---|
E |
The nth element. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if n < 0 or n >= size() |
popFirst
fun popFirst(): E
Remove first element from front of the CircularArray and return it.
| Returns | |
|---|---|
E |
The element removed. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |
popLast
fun popLast(): E
Remove last element from end of the CircularArray and return it.
| Returns | |
|---|---|
E |
The element removed. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |
removeFromEnd
fun removeFromEnd(count: Int): Unit
Remove multiple elements from end of the CircularArray, ignore when count is less than or equals to 0.
| Parameters | |
|---|---|
count: Int |
Number of elements to remove. |
removeFromStart
fun removeFromStart(count: Int): Unit
Remove multiple elements from front of the CircularArray, ignore when count is less than or equal to 0.
| Parameters | |
|---|---|
count: Int |
Number of elements to remove. |
size
fun size(): Int
Get number of elements in the CircularArray.
| Returns | |
|---|---|
Int |
Number of elements in the |
Public properties
first
val first: E
Get first element of the CircularArray.
| Returns | |
|---|---|
E |
The first element. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |
last
val last: E
Get last element of the CircularArray.
| Returns | |
|---|---|
E |
The last element. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |