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 |
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 int |
getFirst()Get first integer of the |
final int |
getLast()Get last 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 constructors
CircularIntArray
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
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 |
if n < 0 or n >= size(). |
getFirst
public final int getFirst()
Get first integer of the CircularIntArray.
| Returns | |
|---|---|
int |
The first integer. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |
getLast
public final int getLast()
Get last integer of the CircularIntArray.
| Returns | |
|---|---|
int |
The last integer. |
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if |
isEmpty
public final boolean isEmpty()
Return true if size is 0.
| Returns | |
|---|---|
boolean |
|
popFirst
public final int popFirst()
Remove first integer from front of the CircularIntArray and return it.
| Returns | |
|---|---|
int |
The integer removed. |
| Throws | |
|---|---|
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 |
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. |
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 |
if numOfElements is larger than |
size
public final int size()
Get number of integers in the CircularIntArray.
| Returns | |
|---|---|
int |
Number of integers in the |