Package org.infinispan.commons.util
Class ArrayRingBuffer<T>
java.lang.Object
org.infinispan.commons.util.ArrayRingBuffer<T>
It's a growable ring buffer that allows to move tail/head sequences, clear, append, set/replace at specific positions.
This version requires headSequence to always be pointing at the first non null value if one is present.
- Author:
- Francesco Nigro
-
Constructor Summary
ConstructorsConstructorDescriptionArrayRingBuffer
(int initialSize) ArrayRingBuffer
(int initialSize, long headSequence) -
Method Summary
Modifier and TypeMethodDescriptionvoid
int
void
clear()
boolean
contains
(long index) int
dropHeadUntil
(long indexExclusive) Remove all elements fromheadSequence
to at leastindexExclusive
until a non null value is found if present.
At the end of this operationheadSequence
will be greater than or equalindexExclusive
.int
dropTailTo
(long indexInclusive) Remove all elements fromtailSequence
back toindexInclusive
.
At the end of this operationtailSequence
is equals toindexInclusive
.void
void
forEach
(ObjLongConsumer<? super T> consumer) get
(long index) long
long
boolean
isEmpty()
peek()
poll()
Removes the element at head, does not catch up the headSequence but will incrementremove
(long index) Removes an element at indexint
size()
int
size
(boolean count_null_elements) toString()
-
Constructor Details
-
ArrayRingBuffer
public ArrayRingBuffer() -
ArrayRingBuffer
public ArrayRingBuffer(int initialSize) -
ArrayRingBuffer
public ArrayRingBuffer(int initialSize, long headSequence)
-
-
Method Details
-
size
public int size() -
size
public int size(boolean count_null_elements) -
getTailSequence
public long getTailSequence() -
getHeadSequence
public long getHeadSequence() -
forEach
-
availableCapacityWithoutResizing
public int availableCapacityWithoutResizing() -
contains
public boolean contains(long index) -
dropTailToHead
public void dropTailToHead() -
clear
public void clear() -
dropTailTo
public int dropTailTo(long indexInclusive) Remove all elements fromtailSequence
back toindexInclusive
.
At the end of this operationtailSequence
is equals toindexInclusive
. Note there can be null values betweentailSequence
andheadSequence
as onlyheadSequence
is caught up to a non null value on modification.eg: elements = [A, B, C] tail = 3 head = 0 dropTailTo(1) elements = [A] tail = 1 head = 0
-
dropHeadUntil
public int dropHeadUntil(long indexExclusive) Remove all elements fromheadSequence
to at leastindexExclusive
until a non null value is found if present.
At the end of this operationheadSequence
will be greater than or equalindexExclusive
. If there are no more values left thenheadSequence
will equaltailSequence
.eg: elements = [A, B, C] tail = 3 head = 0 dropHeadUntil(1) elements = [B, C] tail = 3 head = 1
-
get
-
set
-
add
-
isEmpty
public boolean isEmpty() -
peek
-
poll
Removes the element at head, does not catch up the headSequence but will increment -
remove
Removes an element at index -
toString
-