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 fields |
|
|---|---|
final int |
Get first integer of the |
final int |
Get last integer of the |
Public constructors |
|
|---|---|
CircularIntArray(int minCapacity)Creates a circular array with capacity for at least |
|
Public methods |
|
|---|---|
final void |
addFirst(int element)Add an integer in front of the |
final void |
addLast(int element)Add an integer at end of the |
final void |
clear()Remove all integers from the |
final int |
get(int index)Get nth (0 <= n <= size()-1) integer of the |
final boolean |
isEmpty()Return |
final int |
popFirst()Remove first integer from front of the |
final int |
popLast()Remove last integer from end of the |
final void |
removeFromEnd(int count)Remove multiple elements from end of the |
final void |
removeFromStart(int count)Remove multiple integers from front of the |
final int |
size()Get number of integers in the |
Public fields
first
public final int first
Get first integer of the CircularIntArray.
| Returns | |
|---|---|
int |
The first integer. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException kotlin.IndexOutOfBoundsException |
if |
last
public final int last
Get last integer of the CircularIntArray.
| Returns | |
|---|---|
int |
The last integer. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException kotlin.IndexOutOfBoundsException |
if |
Public constructors
CircularIntArray
public final 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
public final void addFirst(int element)
Add an integer in front of the CircularIntArray.
| Parameters | |
|---|---|
int element |
|
addLast
public final void addLast(int element)
Add an integer at end of the CircularIntArray.
| Parameters | |
|---|---|
int element |
|
get
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 |
| Returns | |
|---|---|
int |
The nth integer. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException kotlin.IndexOutOfBoundsException |
if n < 0 or n >= size(). |
popFirst
public final int popFirst()
Remove first integer from front of the CircularIntArray and return it.
| Returns | |
|---|---|
int |
The integer removed. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException kotlin.IndexOutOfBoundsException |
if |
popLast
public final int popLast()
Remove last integer from end of the CircularIntArray and return it.
| Returns | |
|---|---|
int |
The integer removed. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException kotlin.IndexOutOfBoundsException |
if |
removeFromEnd
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 kotlin.IndexOutOfBoundsException |
|
removeFromStart
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 kotlin.IndexOutOfBoundsException |
if numOfElements is larger than |
size
public final int size()
Get number of integers in the CircularIntArray.
| Returns | |
|---|---|
int |
Number of integers in the |