CircularArray

class CircularArray<E> constructor(minCapacity: Int = 8)(source)

CircularArray is a generic circular array data structure that provides O(1) random read, O(1) prepend and O(1) append. The CircularArray automatically grows its capacity when number of added items is over its capacity.

Parameters

minCapacity

the minimum capacity, between 1 and 2^30 inclusive

Constructors

Link copied to clipboard
fun CircularArray(minCapacity: Int = 8)

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

Functions

Link copied to clipboard
fun addFirst(element: E)

Add an element in front of the CircularArray.

Link copied to clipboard
fun addLast(element: E)

Add an element at end of the CircularArray.

Link copied to clipboard
fun clear()

Remove all elements from the CircularArray.

Link copied to clipboard
operator fun get(index: Int): E

Get nth (0 <= n <= size()-1) element of the CircularArray.

Link copied to clipboard

Return true if size is 0.

Link copied to clipboard
fun popFirst(): E

Remove first element from front of the CircularArray and return it.

Link copied to clipboard
fun popLast(): E

Remove last element from end of the CircularArray and return it.

Link copied to clipboard
fun removeFromEnd(count: Int)

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

Link copied to clipboard
fun removeFromStart(count: Int)

Remove multiple elements from front of the CircularArray, ignore when count is less than or equal to 0.

Link copied to clipboard
fun size(): Int

Get number of elements in the CircularArray.

Properties

Link copied to clipboard
val first: E

Get first element of the CircularArray.

Link copied to clipboard
val last: E

Get last element of the CircularArray.