E
- public final class IndexedRingBuffer<E> extends java.lang.Object implements Subscription
This is meant for hundreds or single-digit thousands of elements that need to be rapidly added and randomly or sequentially removed while avoiding object allocation.
On Intel Core i7, 2.3Mhz, Mac Java 8:
- adds per second single-threaded => ~32,598,500 for 100 - adds per second single-threaded => ~23,200,000 for 10,000 - adds + removes per second single-threaded => 15,562,100 for 100 - adds + removes per second single-threaded => 8,760,000 for 10,000
Benchmark (size) Mode Samples Score Score error Units
r.i.IndexedRingBufferPerf.indexedRingBufferAdd 100 thrpt 5 263571.721 9856.994 ops/s
r.i.IndexedRingBufferPerf.indexedRingBufferAdd 10000 thrpt 5 1763.417 211.998 ops/s
r.i.IndexedRingBufferPerf.indexedRingBufferAddRemove 100 thrpt 5 139850.115 17143.705 ops/s
r.i.IndexedRingBufferPerf.indexedRingBufferAddRemove 10000 thrpt 5 809.982 72.931 ops/s
Modifier and Type | Method and Description |
---|---|
int |
add(E e)
Add an element and return the index where it was added to allow removal.
|
int |
forEach(Func1<? super E,java.lang.Boolean> action) |
int |
forEach(Func1<? super E,java.lang.Boolean> action,
int startIndex) |
static IndexedRingBuffer |
getInstance() |
boolean |
isUnsubscribed()
Indicates whether this
Subscription is currently unsubscribed. |
void |
releaseToPool()
This resets the arrays, nulls out references and returns it to the pool.
|
E |
remove(int index) |
void |
unsubscribe()
Stops the receipt of notifications on the
Subscriber that was registered when this Subscription
was received. |
public static final IndexedRingBuffer getInstance()
public void releaseToPool()
public void unsubscribe()
Subscription
Subscriber
that was registered when this Subscription
was received.
This allows unregistering an Subscriber
before it has finished receiving all events (i.e. before
onCompleted is called).
unsubscribe
in interface Subscription
public int add(E e)
e
- public E remove(int index)
public boolean isUnsubscribed()
Subscription
Subscription
is currently unsubscribed.isUnsubscribed
in interface Subscription
true
if this Subscription
is currently unsubscribed, false
otherwise