CircularIntArray
-
Cmn
class CircularIntArray
CircularIntArray is a circular integer array data structure that provides O(1) random read, O(1) prepend and O(1) append. The CircularIntArray automatically grows its capacity when number of added integers is over its capacity.
Summary
Public constructors |
|
|---|---|
CircularIntArray(minCapacity: Int)Creates a circular array with capacity for at least |
Cmn
|
Public functions |
||
|---|---|---|
Unit |
Add an integer in front of the |
Cmn
|
Unit |
Add an integer at end of the |
Cmn
|
Unit |
clear()Remove all integers from the |
Cmn
|
operator Int |
Get nth (0 <= n <= size()-1) integer of the |
Cmn
|
Boolean |
isEmpty()Return |
Cmn
|
Int |
popFirst()Remove first integer from front of the |
Cmn
|
Int |
popLast()Remove last integer from end of the |
Cmn
|
Unit |
removeFromEnd(count: Int)Remove multiple elements from end of the |
Cmn
|
Unit |
removeFromStart(count: Int)Remove multiple integers from front of the |
Cmn
|
Int |
size()Get number of integers in the |
Cmn
|
Public properties |
||
|---|---|---|
Int |
Get first integer of the |
Cmn
|
Int |
Get last integer of the |
Cmn
|
Public constructors
CircularIntArray
CircularIntArray(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
get
operator fun get(index: Int): Int
Get nth (0 <= n <= size()-1) integer of the CircularIntArray.
| Parameters | |
|---|---|
index: Int |
The zero based element index in the |
| Returns | |
|---|---|
Int |
The nth integer. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if n < 0 or n >= size(). |
popFirst
fun popFirst(): Int
Remove first integer from front of the CircularIntArray and return it.
| Returns | |
|---|---|
Int |
The integer removed. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |
popLast
fun popLast(): Int
Remove last integer from end of the CircularIntArray and return it.
| Returns | |
|---|---|
Int |
The integer removed. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |
removeFromEnd
fun removeFromEnd(count: Int): Unit
Remove multiple elements from end of the CircularIntArray, ignore when count is less than or equals to 0.
| Parameters | |
|---|---|
count: Int |
Number of integers to remove. |
removeFromStart
fun removeFromStart(count: Int): Unit
Remove multiple integers from front of the CircularIntArray, ignore when count is less than or equals to 0.
| Parameters | |
|---|---|
count: Int |
Number of integers to remove. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if numOfElements is larger than |
size
fun size(): Int
Get number of integers in the CircularIntArray.
| Returns | |
|---|---|
Int |
Number of integers in the |
Public properties
first
val first: Int
Get first integer of the CircularIntArray.
| Returns | |
|---|---|
Int |
The first integer. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |
last
val last: Int
Get last integer of the CircularIntArray.
| Returns | |
|---|---|
Int |
The last integer. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |