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

Creates a circular array with default capacity.

<init>(minCapacity: Int)

Creates a circular array with capacity for at least minCapacity elements.

Public methods

Unit

Add an integer in front of the CircularIntArray.

Unit

Add an integer at end of the CircularIntArray.

Unit

Remove all integers from the CircularIntArray.

Int
get(n: Int)

Get nth (0 <= n <= size()-1) integer of the CircularIntArray.

Int

Get first integer of the CircularIntArray.

Int

Get last integer of the CircularIntArray.

Boolean

Return true if size() is 0.

Int

Remove first integer from front of the CircularIntArray and return it.

Int

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

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.

clear

fun clear(): Unit

Remove all integers from the CircularIntArray.

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.

isEmpty

fun isEmpty(): Boolean

Return true if size() is 0.

Return
Boolean: true if size() is 0.

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()

size

fun size(): Int

Get number of integers in the CircularIntArray.

Return
Int: Number of integers in the CircularIntArray.