CircularIntArray
class CircularIntArray
kotlin.Any | |
↳ | androidx.collection.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 | |
---|---|
<init>() Creates a circular array with default capacity. |
|
Creates a circular array with capacity for at least |
Public methods | |
---|---|
Unit |
Add an integer in front of the CircularIntArray. |
Unit |
Add an integer at end of the CircularIntArray. |
Unit |
clear() Remove all integers from the CircularIntArray. |
Int |
Get nth (0 <= n <= size()-1) integer of the CircularIntArray. |
Int |
getFirst() Get first integer of the CircularIntArray. |
Int |
getLast() Get last integer of the CircularIntArray. |
Boolean |
isEmpty() Return true if size() is 0. |
Int |
popFirst() Remove first integer from front of the CircularIntArray and return it. |
Int |
popLast() Remove last integer from end of the CircularIntArray and return it. |
Unit |
removeFromEnd(numOfElements: Int) Remove multiple elements from end of the CircularIntArray, ignore when numOfElements is less than or equals to 0. |
Unit |
removeFromStart(numOfElements: Int) Remove multiple integers from front of the CircularIntArray, ignore when numOfElements is less than or equals to 0. |
Int |
size() Get number of integers in the CircularIntArray. |
Public constructors
<init>
CircularIntArray()
Creates a circular array with default capacity.
<init>
CircularIntArray(minCapacity: Int)
Creates a circular array with capacity for at least minCapacity
elements.
Parameters | |
---|---|
minCapacity |
Int: the minimum capacity, between 1 and 2^30 inclusive |
Public methods
addFirst
fun addFirst(e: Int): Unit
Add an integer in front of the CircularIntArray.
Parameters | |
---|---|
e |
Int: Integer to add. |
addLast
fun addLast(e: Int): Unit
Add an integer at end of the CircularIntArray.
Parameters | |
---|---|
e |
Int: Integer to add. |
get
fun get(n: Int): Int
Get nth (0 <= n <= size()-1) integer of the CircularIntArray.
Parameters | |
---|---|
n |
Int: The zero based element index in the CircularIntArray. |
Return | |
---|---|
Int |
The nth integer. |
Exceptions | |
---|---|
|
ArrayIndexOutOfBoundsException if n < 0 or n >= size(). |
getFirst
fun getFirst(): Int
Get first integer of the CircularIntArray.
Return | |
---|---|
Int |
The first integer. |
Exceptions | |
---|---|
|
ArrayIndexOutOfBoundsException if CircularIntArray is empty. |
getLast
fun getLast(): Int
Get last integer of the CircularIntArray.
Return | |
---|---|
Int |
The last integer. |
Exceptions | |
---|---|
|
ArrayIndexOutOfBoundsException if CircularIntArray is empty. |
popFirst
fun popFirst(): Int
Remove first integer from front of the CircularIntArray and return it.
Return | |
---|---|
Int |
The integer removed. |
Exceptions | |
---|---|
ArrayIndexOutOfBoundsException |
if CircularIntArray is empty. |
popLast
fun popLast(): Int
Remove last integer from end of the CircularIntArray and return it.
Return | |
---|---|
Int |
The integer removed. |
Exceptions | |
---|---|
ArrayIndexOutOfBoundsException |
if CircularIntArray is empty. |
removeFromEnd
fun removeFromEnd(numOfElements: Int): Unit
Remove multiple elements from end of the CircularIntArray, ignore when numOfElements is less than or equals to 0.
Parameters | |
---|---|
numOfElements |
Int: Number of integers to remove. |
Exceptions | |
---|---|
ArrayIndexOutOfBoundsException |
if numOfElements is larger than size() |
removeFromStart
fun removeFromStart(numOfElements: Int): Unit
Remove multiple integers from front of the CircularIntArray, ignore when numOfElements is less than or equals to 0.
Parameters | |
---|---|
numOfElements |
Int: Number of integers to remove. |
Exceptions | |
---|---|
ArrayIndexOutOfBoundsException |
if numOfElements is larger than size() |