final class RankedSequence<T> extends java.util.concurrent.atomic.AtomicReference<RankedSequence.Content> implements java.lang.Iterable<T>
List that arranges elements by descending rank; supports concurrent iteration and modification.| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
RankedSequence.Content
Represents an immutable snapshot of ranked elements.
|
(package private) class |
RankedSequence.Itr
Custom
Iterator that copes with modification by repositioning itself in the updated list. |
| Modifier and Type | Field and Description |
|---|---|
private static long |
serialVersionUID |
| Constructor and Description |
|---|
RankedSequence() |
RankedSequence(RankedSequence<T> sequence) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
contains(java.lang.Object element) |
boolean |
containsThis(java.lang.Object element) |
void |
insert(T element,
int rank)
Inserts the given element into the ordered list, using the assigned rank as a guide.
|
boolean |
isEmpty() |
RankedSequence.Itr |
iterator() |
T |
peek() |
(package private) static long |
rank2uid(int rank,
int uniq)
Turns the given (potentially non-unique) rank into a unique id by appending a counter.
|
T |
remove(java.lang.Object element) |
boolean |
removeThis(T element) |
(package private) static int |
safeBinarySearch(long[] uids,
long uid)
Finds the insertion point with the nearest UID, regardless of whether the UID is in the list or not.
|
int |
size() |
java.lang.Iterable<T> |
snapshot() |
(package private) static int |
uid2rank(long uid)
Extracts the original (potentially non-unique) assigned rank from the given unique id.
|
accumulateAndGet, compareAndSet, get, getAndAccumulate, getAndSet, getAndUpdate, lazySet, set, toString, updateAndGet, weakCompareAndSetprivate static final long serialVersionUID
RankedSequence()
RankedSequence(RankedSequence<T> sequence)
public void insert(T element, int rank)
The rank can be any value from Integer.MIN_VALUE to Integer.MAX_VALUE.
element - The element to insertrank - The assigned rankpublic T peek()
public boolean contains(java.lang.Object element)
public boolean containsThis(java.lang.Object element)
public T remove(java.lang.Object element)
public boolean removeThis(T element)
public java.lang.Iterable<T> snapshot()
public void clear()
public boolean isEmpty()
public int size()
public RankedSequence.Itr iterator()
iterator in interface java.lang.Iterable<T>static long rank2uid(int rank,
int uniq)
rank - The assigned rankuniq - The unique counterstatic int uid2rank(long uid)
uid - The unique idstatic int safeBinarySearch(long[] uids,
long uid)
Unlike Arrays.binarySearch(long[], long) this will always return a number from zero to size() inclusive.
uids - The UIDs arrayuid - The UID to find