Interface OrderedKeys

All Superinterfaces:
AutoCloseable, LongSizedDataStructure, SafeCloseable
All Known Subinterfaces:
Index, ReadOnlyIndex, SingleRangeMixin
All Known Implementing Classes:
CurrentOnlyIndex, OrderedKeysAsChunkImpl, OrderedKeysKeyIndicesChunkImpl, OrderedKeysKeyRangesChunkImpl, RspOrderedKeys, ShiftedOrderedKeys, SingleRangeOrderedKeys, SortedIndex, SortedRangesOrderedKeys, TreeIndex

public interface OrderedKeys
extends SafeCloseable, LongSizedDataStructure
An ordered collection of long keys.
  • Field Details

    • EMPTY

      static final OrderedKeys EMPTY
      Immutable, re-usable OrderedKeys instance.
  • Method Details

    • wrapKeyIndicesChunkAsOrderedKeys

      static OrderedKeys wrapKeyIndicesChunkAsOrderedKeys​(LongChunk<Attributes.OrderedKeyIndices> longChunk)
      Wrap a LongChunk as an OrderedKeys.
      Parameters:
      longChunk - A chunk to wrap as a new OrderedKeys object.
      Returns:
      A new OrderedKeys object, who does not own the passed chunk.
    • wrapKeyRangesChunkAsOrderedKeys

      static OrderedKeys wrapKeyRangesChunkAsOrderedKeys​(LongChunk<Attributes.OrderedKeyRanges> longChunk)
      Wrap a LongChunk as an OrderedKeys.
      Parameters:
      longChunk - A chunk to wrap as a new OrderedKeys object.
      Returns:
      A new OrderedKeys object, who does not own the passed chunk.
    • takeKeyIndicesChunkAndMakeOrderedKeys

      static OrderedKeys takeKeyIndicesChunkAndMakeOrderedKeys​(WritableLongChunk<Attributes.OrderedKeyIndices> longChunk)
      Create and return a new OrderedKeys object from the provided WritableLongChunk.
      Parameters:
      longChunk - The input chunk. The returned object will take ownership of this chunk.
      Returns:
      A new OrderedKeys object, who owns the passed chunk.
    • takeKeyRangesChunkAndMakeOrderedKeys

      static OrderedKeys takeKeyRangesChunkAndMakeOrderedKeys​(WritableLongChunk<Attributes.OrderedKeyRanges> longChunk)
      Create and return a new OrderedKeys object from the provided WritableLongChunk.
      Parameters:
      longChunk - The input chunk. The returned object will take ownership of this chunk.
      Returns:
      A new OrderedKeys object, who owns the passed chunk.
    • getOrderedKeysIterator

      OrderedKeys.Iterator getOrderedKeysIterator()
      Get an OrderedKeys.Iterator over this OrderedKeys.
      Returns:
      A new iterator, positioned at the first key
    • getOrderedKeysByPosition

      OrderedKeys getOrderedKeysByPosition​(long startPositionInclusive, long length)

      Get an ordered subset of the keys in this OrderedKeys for a position range. The result will contain the set of keys in this that lie at positions in the half-open range [startPositionInclusive, startPositionInclusive + length). The returned reference is owned by the caller, who should call close() when it is done with it.

      Parameters:
      startPositionInclusive - The position of the first key to include
      length - The number of keys to include
      Returns:
      The subset as an OrderedKeys, which may be this
    • getOrderedKeysByKeyRange

      OrderedKeys getOrderedKeysByKeyRange​(long startKeyInclusive, long endKeyInclusive)

      Get an ordered subset of the keys in this OrderedKeys for a key range. The returned set will be the intersection of the keys in this with the keys in the closed interval [startKeyInclusive, endKeyInclusive]. The returned reference is owned by the caller, who should call close() when it is done with it.

      Parameters:
      startKeyInclusive - The minimum key to include
      endKeyInclusive - The maximum key to include
      Returns:
      The subset as an OrderedKeys, which may be this
    • asIndex

      Index asIndex()
      Get an Index representation of this OrderedKeys.
      Returns:
      An Index representation for the same keys in the same order
      ApiNote:
      If you use the result across clock ticks, you may observe inconsistencies., You must not mutate the result.
    • asKeyIndicesChunk

      Get a LongChunk representation of the individual keys in this OrderedKeys.
      Returns:
      A LongChunk containing the keys in this OrderedKeys
      ApiNote:
      This OrderedKeys owns the result, which is valid only as long as this OrderedKeys remains valid., You must not mutate the result.
    • asKeyRangesChunk

      Get a LongChunk representation of key ranges in this OrderedKeys.
      Returns:
      A LongChunk containing the key ranges in this OrderedKeys
      ApiNote:
      This OrderedKeys owns the result, which is valid only as long as this OrderedKeys remains valid., You must not mutate the result.
    • fillKeyIndicesChunk

      void fillKeyIndicesChunk​(WritableLongChunk<? extends Attributes.KeyIndices> chunkToFill)

      Fill the supplied WritableLongChunk with individual keys from this OrderedKeys.

      The chunk's capacity is assumed to be big enough.

      Parameters:
      chunkToFill - A chunk to fill with individual keys
    • fillKeyRangesChunk

      void fillKeyRangesChunk​(WritableLongChunk<Attributes.OrderedKeyRanges> chunkToFill)

      Fill the supplied WritableLongChunk with key ranges from this OrderedKeys.

      The chunk's capacity is assumed to be big enough.

      Parameters:
      chunkToFill - A chunk to fill with key ranges
    • isEmpty

      boolean isEmpty()
      True if the size of this Orderedkeys is zero.
      Returns:
      True if there are no elements in this OrderedKeys.
    • firstKey

      long firstKey()
      Get the first key in this OrderedKeys.
      Returns:
      The first key, or ReadOnlyIndex.NULL_KEY if there is none.
    • lastKey

      long lastKey()
      Get the last key in this OrderedKeys.
      Returns:
      The last key, or ReadOnlyIndex.NULL_KEY if there is none.
    • size

      long size()
      Get the number of keys in this OrderedKeys.
      Specified by:
      size in interface LongSizedDataStructure
      Returns:
      The size, in [0, Long.MAX_VALUE]
    • isContiguous

      default boolean isContiguous()
      Helper to tell you if this is one contiguous range.
    • getAverageRunLengthEstimate

      long getAverageRunLengthEstimate()

      Get an estimate of the average (mean) length of runs of adjacent keys in this OrderedKeys.

      Implementations should strive to keep this method efficient (O(1) preferred) at the expense of accuracy.

      Empty OrderedKeys should return an arbitrary valid value, usually 1.

      Returns:
      An estimate of the average run length in this OrderedKeys, in [1, size()]
    • forEachLong

      boolean forEachLong​(LongAbortableConsumer lac)
      For as long as the consumer wants more keys, call accept on the consumer with the individual key instances in this OrderedKeys, in increasing order.
      Parameters:
      lac - a consumer to feed the individual key values to.
      Returns:
      false if the consumer provided ever returned false, true otherwise.
    • forEachLongRange

      boolean forEachLongRange​(LongRangeAbortableConsumer larc)
      For as long as the consumer wants more ranges, call accept on the consumer with the individual key ranges in this OrderedKeys, in increasing order.
      Parameters:
      larc - a consumer to feed the individual key values to.
      Returns:
      false if the consumer provided ever returned false, true otherwise.
    • forAllLongs

      default void forAllLongs​(LongConsumer lc)
    • forAllLongRanges

      default void forAllLongRanges​(LongRangeConsumer lrc)
    • close

      default void close()

      Free any resources associated with this object.

      Using any OrderedKeys methods after close() is an error and may produce exceptions or undefined results.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SafeCloseable
    • forRange

      static OrderedKeys forRange​(long firstKey, long lastKey)