Class RankedSequence<T>

All Implemented Interfaces:
Serializable, Iterable<T>

final class RankedSequence<T> extends AtomicReference<RankedSequence.Content> implements Iterable<T>
Ordered List that arranges elements by descending rank; supports concurrent iteration and modification.
  • Field Details

  • Constructor Details

    • RankedSequence

      RankedSequence()
    • RankedSequence

      RankedSequence(RankedSequence<T> sequence)
  • Method Details

    • insert

      public void insert(T element, int rank)
      Inserts the given element into the ordered list, using the assigned rank as a guide.

      The rank can be any value from Integer.MIN_VALUE to Integer.MAX_VALUE.

      Parameters:
      element - The element to insert
      rank - The assigned rank
    • peek

      public T peek()
    • contains

      public boolean contains(Object element)
    • containsThis

      public boolean containsThis(Object element)
    • remove

      public T remove(Object element)
    • removeThis

      public boolean removeThis(T element)
    • snapshot

      public Iterable<T> snapshot()
    • clear

      public void clear()
    • isEmpty

      public boolean isEmpty()
    • size

      public int size()
    • iterator

      public RankedSequence<T>.Itr iterator()
      Specified by:
      iterator in interface Iterable<T>
    • rank2uid

      static long rank2uid(int rank, int uniq)
      Turns the given (potentially non-unique) rank into a unique id by appending a counter.
      Parameters:
      rank - The assigned rank
      uniq - The unique counter
      Returns:
      The unique id
    • uid2rank

      static int uid2rank(long uid)
      Extracts the original (potentially non-unique) assigned rank from the given unique id.
      Parameters:
      uid - The unique id
      Returns:
      Assigned rank
    • safeBinarySearch

      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.

      Unlike Arrays.binarySearch(long[], long) this will always return a number from zero to size() inclusive.

      Parameters:
      uids - The UIDs array
      uid - The UID to find
      Returns:
      Index with nearest UID