CircularIntArray


public final 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(int minCapacity)

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

Public methods

final void
addFirst(int element)

Add an integer in front of the CircularIntArray.

final void
addLast(int element)

Add an integer at end of the CircularIntArray.

final void

Remove all integers from the CircularIntArray.

final int
get(int index)

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

final int

Get first integer of the CircularIntArray.

final int

Get last integer of the CircularIntArray.

final boolean

Return true if size is 0.

final int

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

final int

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

final void
removeFromEnd(int count)

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

final void
removeFromStart(int count)

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

final int

Get number of integers in the CircularIntArray.

Public constructors

CircularIntArray

Added in 1.0.0
public CircularIntArray(int minCapacity)

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

Parameters
int minCapacity

the minimum capacity, between 1 and 2^30 inclusive

Public methods

addFirst

Added in 1.0.0
public final void addFirst(int element)

Add an integer in front of the CircularIntArray.

Parameters
int element

Int to add.

addLast

Added in 1.0.0
public final void addLast(int element)

Add an integer at end of the CircularIntArray.

Parameters
int element

Int to add.

clear

Added in 1.0.0
public final void clear()

Remove all integers from the CircularIntArray.

get

Added in 1.0.0
public final int get(int index)

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

Parameters
int index

The zero based element index in the CircularIntArray.

Returns
int

The nth integer.

Throws
kotlin.IndexOutOfBoundsException

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

getFirst

Added in 1.0.0
public final int getFirst()

Get first integer of the CircularIntArray.

Returns
int

The first integer.

getLast

Added in 1.0.0
public final int getLast()

Get last integer of the CircularIntArray.

Returns
int

The last integer.

isEmpty

Added in 1.0.0
public final boolean isEmpty()

Return true if size is 0.

Returns
boolean

true if size is 0.

popFirst

Added in 1.0.0
public final int popFirst()

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

Returns
int

The integer removed.

popLast

Added in 1.0.0
public final int popLast()

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

Returns
int

The integer removed.

removeFromEnd

Added in 1.0.0
public final void removeFromEnd(int count)

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

Parameters
int count

Number of integers to remove.

Throws
kotlin.IndexOutOfBoundsException

if count is larger than size

removeFromStart

Added in 1.0.0
public final void removeFromStart(int count)

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

Parameters
int count

Number of integers to remove.

Throws
kotlin.IndexOutOfBoundsException

if numOfElements is larger than size

size

Added in 1.0.0
public final int size()

Get number of integers in the CircularIntArray.

Returns
int

Number of integers in the CircularIntArray.