Package org.ddogleg.struct
Class CircularArray<T>
java.lang.Object
org.ddogleg.struct.CircularArray<T>
A circular queue which can grow as needed.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new element to the queue.void
Adds a new element to the queue, but if the queue is full write over the oldest element.protected T
get
(int index) Returns the element in the queue at index.grow()
Adds a new element to the end of the list and returns it.growW()
Adds a new element to the end of the list and returns it.head()
Value of the first element in the queueboolean
isEmpty()
boolean
isFull()
popHead()
Returns and removes the first element from the queue.popTail()
Returns and removes the last element from the queue.void
Removes the first elementvoid
Removes the last elementvoid
reset()
int
size()
tail()
Value of the last element in the queue
-
Field Details
-
data
-
start
public int start -
size
public int size
-
-
Constructor Details
-
CircularArray
-
CircularArray
-
-
Method Details
-
reset
public void reset() -
popHead
Returns and removes the first element from the queue.- Returns:
- first element in the queue
-
popTail
Returns and removes the last element from the queue.- Returns:
- last element in the queue
-
head
Value of the first element in the queue -
tail
Value of the last element in the queue -
removeHead
public void removeHead()Removes the first element -
removeTail
public void removeTail()Removes the last element -
get
Returns the element in the queue at index. No bounds check is performed and a garbage value might be returned.- Parameters:
index
- Which element in the queue you wish to access- Returns:
- the element's value
-
grow
Adds a new element to the end of the list and returns it. If the inner array isn't large enough then it will grow.- Returns:
- instance at the tail
-
growW
Adds a new element to the end of the list and returns it. If the inner array isn't large enough then the oldest element will be written over.- Returns:
- instance at the tail
-
add
Adds a new element to the queue. If the queue isn't large enough to store this value then its internal data array will grow- Parameters:
value
- Value which is to be added
-
addW
Adds a new element to the queue, but if the queue is full write over the oldest element.- Parameters:
value
- Value which is to be added
-
size
public int size() -
isEmpty
public boolean isEmpty() -
isFull
public boolean isFull() -
createInstance
-