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 minCapacity elements.

Cmn

Public functions

Unit
addFirst(element: Int)

Add an integer in front of the CircularIntArray.

Cmn
Unit
addLast(element: Int)

Add an integer at end of the CircularIntArray.

Cmn
Unit

Remove all integers from the CircularIntArray.

Cmn
operator Int
get(index: Int)

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

Cmn
Boolean

Return true if size is 0.

Cmn
Int

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

Cmn
Int

Remove last integer from end of the CircularIntArray and return it.

Cmn
Unit

Remove multiple elements from end of the CircularIntArray, ignore when count is less than or equals to 0.

Cmn
Unit

Remove multiple integers from front of the CircularIntArray, ignore when count is less than or equals to 0.

Cmn
Int

Get number of integers in the CircularIntArray.

Cmn

Public properties

Int

Get first integer of the CircularIntArray.

Cmn
Int

Get last integer of the CircularIntArray.

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

addFirst

fun addFirst(element: Int): Unit

Add an integer in front of the CircularIntArray.

Parameters
element: Int

Int to add.

addLast

fun addLast(element: Int): Unit

Add an integer at end of the CircularIntArray.

Parameters
element: Int

Int to add.

clear

fun clear(): Unit

Remove all integers from the CircularIntArray.

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 CircularIntArray.

Returns
Int

The nth integer.

Throws
kotlin.IndexOutOfBoundsException

if n < 0 or n >= size().

isEmpty

fun isEmpty(): Boolean

Return true if size is 0.

Returns
Boolean

true if size is 0.

popFirst

fun popFirst(): Int

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

Returns
Int

The integer removed.

popLast

fun popLast(): Int

Remove last integer from end of the CircularIntArray and return it.

Returns
Int

The integer removed.

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.

Throws
kotlin.IndexOutOfBoundsException

if count is larger than size

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

size

fun size(): Int

Get number of integers in the CircularIntArray.

Returns
Int

Number of integers in the CircularIntArray.

Public properties

first

val firstInt

Get first integer of the CircularIntArray.

Returns
Int

The first integer.

last

val lastInt

Get last integer of the CircularIntArray.

Returns
Int

The last integer.