Class WritableRowSetImpl

java.lang.Object
io.deephaven.engine.rowset.impl.RowSequenceAsChunkImpl
io.deephaven.engine.rowset.impl.WritableRowSetImpl
All Implemented Interfaces:
LogOutputAppendable, RowSequence, RowSet, WritableRowSet, LongSizedDataStructure, SafeCloseable, Externalizable, Serializable, AutoCloseable
Direct Known Subclasses:
TrackingWritableRowSetImpl

public class WritableRowSetImpl extends RowSequenceAsChunkImpl implements WritableRowSet, Externalizable
See Also:
  • Constructor Details

    • WritableRowSetImpl

      public WritableRowSetImpl()
    • WritableRowSetImpl

      public WritableRowSetImpl(OrderedLongSet innerSet)
  • Method Details

    • getInnerSet

      @VisibleForTesting public final OrderedLongSet getInnerSet()
    • copy

      public final WritableRowSet copy()
      Description copied from interface: RowSet
      Make a new WritableRowSet with the same row keys as this that is safe for further mutation. As in other operations that return a WritableRowSet, the result must be closed by the caller when it is no longer needed. The result will never be a TrackingRowSet; use WritableRowSet.toTracking() on the result as needed.
      Specified by:
      copy in interface RowSet
      Returns:
      The copied WritableRowSet
    • toTracking

      public TrackingWritableRowSet toTracking()
      Description copied from interface: WritableRowSet

      Destructively convert this WritableRowSet into a TrackingWritableRowSet.

      This is really only suitable when the caller "owns" this WritableRowSet. Programming errors may occur if the any code holds onto references to this rather than the result, because there may be ambiguity about resource ownership.

      Implementations are free to transfer ownership of resources from this object to the result. As such, it is an error to directly use this object afterwards; callers must instead use the returned result.

      It is an error to invoke this on an instance that is already tracking.

      Specified by:
      toTracking in interface WritableRowSet
      Returns:
      A TrackingWritableRowSet constructed from this WritableRowSet, or this if already tracking
    • close

      @OverridingMethodsMustInvokeSuper public void close()
      Description copied from interface: RowSequence

      Free any resources associated with this object.

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

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface RowSequence
      Specified by:
      close in interface RowSet
      Specified by:
      close in interface SafeCloseable
      Overrides:
      close in class RowSequenceAsChunkImpl
    • preMutationHook

      protected void preMutationHook()
    • postMutationHook

      protected void postMutationHook()
    • resetTo

      public void resetTo(@NotNull @NotNull RowSet other)
      Reset this WritableRowSetImpl to match another RowSet by updating the innerSet. This will internally assign this.innerSet to a copy-on-write reference to ((WritableRowSetImpl) other).innerSet. The two sets will diverge when either is modified. To maintain continuity between the sets, this function should be called each UGP cycle.
      Specified by:
      resetTo in interface WritableRowSet
      Parameters:
      other - The RowSet to reset to
    • insert

      public final void insert(long key)
      Description copied from interface: WritableRowSet
      Add a single key to this RowSet if it's not already present.
      Specified by:
      insert in interface WritableRowSet
      Parameters:
      key - The key to add
    • insertRange

      public final void insertRange(long startKey, long endKey)
      Description copied from interface: WritableRowSet
      Add all keys in a closed range to this RowSet if they are not already present.
      Specified by:
      insertRange in interface WritableRowSet
      Parameters:
      startKey - The first key to add
      endKey - The last key to add (inclusive)
    • insert

      public final void insert(LongChunk<OrderedRowKeys> keys, int offset, int length)
      Description copied from interface: WritableRowSet
      Add all of the (ordered) keys in a slice of keys to this RowSet if they are not already present.
      Specified by:
      insert in interface WritableRowSet
      Parameters:
      keys - The LongChunk of OrderedRowKeys to insert
      offset - The offset in keys to begin inserting keys from
      length - The number of keys to insert
    • insert

      public final void insert(RowSet added)
      Description copied from interface: WritableRowSet
      Add all of the keys in added to this RowSet if they are not already present.
      Specified by:
      insert in interface WritableRowSet
      Parameters:
      added - The RowSet to add
    • remove

      public final void remove(long key)
      Description copied from interface: WritableRowSet
      Remove a single key from this RowSet if it's present.
      Specified by:
      remove in interface WritableRowSet
      Parameters:
      key - The key to remove
    • removeRange

      public final void removeRange(long start, long end)
      Description copied from interface: WritableRowSet
      Remove all keys in a closed range from this RowSet if they are present.
      Specified by:
      removeRange in interface WritableRowSet
      Parameters:
      start - The first key to remove
      end - The last key to remove (inclusive)
    • remove

      public final void remove(LongChunk<OrderedRowKeys> keys, int offset, int length)
      Description copied from interface: WritableRowSet
      Remove all of the (ordered) keys in a slice of keys from this RowSet if they are present.
      Specified by:
      remove in interface WritableRowSet
      Parameters:
      keys - The LongChunk of OrderedRowKeys to remove
      offset - The offset in keys to begin removing keys from
      length - The number of keys to remove
    • remove

      public final void remove(RowSet removed)
      Description copied from interface: WritableRowSet
      Remove all of the keys in removed that are present in this RowSet.
      Specified by:
      remove in interface WritableRowSet
      Parameters:
      removed - The RowSet to remove
    • update

      public final void update(RowSet added, RowSet removed)
      Description copied from interface: WritableRowSet
      Simultaneously adds the keys from the first RowSet and removes the keys from the second one. API assumption: the intersection of added and removed is empty.
      Specified by:
      update in interface WritableRowSet
    • retain

      public final void retain(RowSet rowSetToIntersect)
      Description copied from interface: WritableRowSet
      Modifies the RowSet by removing any keys not in the rowSetToIntersect argument.
      Specified by:
      retain in interface WritableRowSet
      Parameters:
      rowSetToIntersect - a rowSet with the keys to retain; any other keys not in rowSetToIntersect will be removed.
    • retainRange

      public final void retainRange(long startRowKey, long endRowKey)
      Description copied from interface: WritableRowSet
      Modifies the RowSet by keeping only keys in the interval [startRowKey, endRowKey]
      Specified by:
      retainRange in interface WritableRowSet
      Parameters:
      startRowKey - beginning of interval of keys to keep.
      endRowKey - endRowKey of interval of keys to keep (inclusive).
    • clear

      public final void clear()
      Specified by:
      clear in interface WritableRowSet
    • shiftInPlace

      public final void shiftInPlace(long shiftAmount)
      Specified by:
      shiftInPlace in interface WritableRowSet
    • insertWithShift

      public final void insertWithShift(long shiftAmount, RowSet other)
      Description copied from interface: WritableRowSet
      For each key in the provided RowSet, shift it by shiftAmount and insert it in the current RowSet.
      Specified by:
      insertWithShift in interface WritableRowSet
      Parameters:
      shiftAmount - the amount to add to each key in the RowSet argument before insertion.
      other - the RowSet with the keys to shift and insert.
    • compact

      public final void compact()
      Description copied from interface: WritableRowSet
      May reclaim some unused memory.
      Specified by:
      compact in interface WritableRowSet
    • size

      public final long size()
      Description copied from interface: RowSet
      How many keys are in this RowSet.
      Specified by:
      size in interface LongSizedDataStructure
      Specified by:
      size in interface RowSequence
      Specified by:
      size in interface RowSet
      Returns:
      the number of keys in this RowSet.
    • isEmpty

      public final boolean isEmpty()
      Description copied from interface: RowSet
      Queries whether this RowSet is empty (i.e. has no keys).
      Specified by:
      isEmpty in interface RowSequence
      Specified by:
      isEmpty in interface RowSet
      Returns:
      true if the size() of this RowSet is zero, false if the size is greater than zero
    • firstRowKey

      public final long firstRowKey()
      Description copied from interface: RowSet
      Get the first row key in this RowSet.
      Specified by:
      firstRowKey in interface RowSequence
      Specified by:
      firstRowKey in interface RowSet
      Returns:
      The first row key, or RowSequence.NULL_ROW_KEY if there is none.
    • lastRowKey

      public final long lastRowKey()
      Description copied from interface: RowSequence
      Get the last row key in this RowSequence.
      Specified by:
      lastRowKey in interface RowSequence
      Specified by:
      lastRowKey in interface RowSet
      Specified by:
      lastRowKey in class RowSequenceAsChunkImpl
      Returns:
      The last row key, or RowSequence.NULL_ROW_KEY if there is none.
    • rangesCountUpperBound

      public final long rangesCountUpperBound()
      Specified by:
      rangesCountUpperBound in class RowSequenceAsChunkImpl
    • getRowSequenceIterator

      public final RowSequence.Iterator getRowSequenceIterator()
      Description copied from interface: RowSequence
      Get an RowSequence.Iterator over this RowSequence.
      Specified by:
      getRowSequenceIterator in interface RowSequence
      Returns:
      A new iterator, positioned at the first row key
    • getRowSequenceByPosition

      public final RowSequence getRowSequenceByPosition(long startPositionInclusive, long length)
      Description copied from interface: RowSequence

      Get an ordered subset of the row keys in this RowSequence for a position range. The result will contain the set of row 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.

      Specified by:
      getRowSequenceByPosition in interface RowSequence
      Parameters:
      startPositionInclusive - The position of the first row key to include
      length - The number of row keys to include
      Returns:
      The subset as an RowSequence, which may be this
    • getRowSequenceByKeyRange

      public final RowSequence getRowSequenceByKeyRange(long startRowKeyInclusive, long endRowKeyInclusive)
      Description copied from interface: RowSequence

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

      Specified by:
      getRowSequenceByKeyRange in interface RowSequence
      Parameters:
      startRowKeyInclusive - The minimum row key to include
      endRowKeyInclusive - The maximum row key to include
      Returns:
      The subset as an RowSequence, which may be this
    • asRowSet

      public final RowSet asRowSet()
      Description copied from interface: RowSequence
      Get a RowSet representation of this RowSequence.
      Specified by:
      asRowSet in interface RowSequence
      Returns:
      A RowSet representation for the same row keys in the same order
    • invert

      public final WritableRowSet invert(RowSet keys, long maximumPosition)
      Description copied from interface: RowSet

      Returns the row positions of keys in the current set as a WritableRowSet, stopping at maximumPosition.

      This can be thought of as an iterative RowSet.find(long) over the values in keys, but all keys must exist within this RowSet, because a RowSet result can not represent negative values.

      Specified by:
      invert in interface RowSet
      Parameters:
      keys - The keys to find positions for
      maximumPosition - The largest position for which we will find a key
      Returns:
      A new WritableRowSet containing the positions of the keys in this RowSet
    • intersect

      @NotNull public final @NotNull WritableRowSet intersect(@NotNull @NotNull RowSet range)
      Description copied from interface: RowSet
      Returns a new RowSet representing the intersection of the current RowSet with the input RowSet
      Specified by:
      intersect in interface RowSet
    • overlaps

      public final boolean overlaps(@NotNull @NotNull RowSet range)
      Description copied from interface: RowSet
      Returns true if a RowSet has any overlap.
      Specified by:
      overlaps in interface RowSet
    • overlapsRange

      public final boolean overlapsRange(long start, long end)
      Description copied from interface: RowSet
      Returns true if this RowSet has any overlap with the provided range.
      Specified by:
      overlapsRange in interface RowSet
      Parameters:
      start - Start of range, inclusive.
      end - End of range, inclusive.
      Returns:
      true if any value x in start <= x <= end is contained in this RowSet.
    • subsetOf

      public final boolean subsetOf(@NotNull @NotNull RowSet other)
      Description copied from interface: RowSet
      Returns true if this RowSet is a (possibly improper) subset of other.
      Specified by:
      subsetOf in interface RowSet
      Returns:
      true if every element of this exists within other
    • minus

      public final WritableRowSet minus(RowSet indexToRemove)
      Description copied from interface: RowSet
      Returns a new RowSet representing the keys of the current set not present inside rowSetToRemove. This operation is equivalent to set difference. This RowSet is not modified.
      Specified by:
      minus in interface RowSet
    • union

      public final WritableRowSet union(RowSet indexToAdd)
      Description copied from interface: RowSet
      Returns a new RowSet representing the keys present in both this RowSet and the argument RowSet.
      Specified by:
      union in interface RowSet
      Parameters:
      indexToAdd - A RowSet whose keys will be joined with our own to produce a new RowSet.
      Returns:
      a new RowSet with the union of the keys in both this RowSet and rowSetToAdd.
    • shift

      public final WritableRowSet shift(long shiftAmount)
      Specified by:
      shift in interface RowSet
    • validate

      public final void validate(String failMsg)
      Specified by:
      validate in interface RowSet
    • forEachRowKey

      public final boolean forEachRowKey(LongAbortableConsumer lc)
      Description copied from interface: RowSet
      Provide each value contained in this RowSet, in increased sorted order to the consumer. If the consumer returns false for a key, stops after that key (does not provide any keys after that key).
      Specified by:
      forEachRowKey in interface RowSequence
      Specified by:
      forEachRowKey in interface RowSet
      Parameters:
      lc - the consumer.
      Returns:
      false if the consumer returned false at some point, true if the consumer always returned true and all values in the RowSet were consumed.
    • forEachRowKeyRange

      public final boolean forEachRowKeyRange(LongRangeAbortableConsumer larc)
      Description copied from interface: RowSequence
      For as long as the consumer wants more ranges, call accept on the consumer with the individual row key ranges in this RowSequence, in increasing order.
      Specified by:
      forEachRowKeyRange in interface RowSequence
      Parameters:
      larc - a consumer to feed the individual row key values to.
      Returns:
      false if the consumer provided ever returned false, true otherwise.
    • subSetByPositionRange

      public final WritableRowSet subSetByPositionRange(long startPos, long endPos)
      Description copied from interface: RowSet
      Get a subset of this RowSet within the specified half-closed range of row positions.
      Specified by:
      subSetByPositionRange in interface RowSet
      Parameters:
      startPos - The first position to included in the output (inclusive)
      endPos - The last position to included in the output (exclusive)
      Returns:
      A new RowSet, containing only positions >= startPos and < endPos
    • subSetByKeyRange

      public final WritableRowSet subSetByKeyRange(long startKey, long endKey)
      Description copied from interface: RowSet
      Get a subset of this RowSet within the specified closed range of row keys.
      Specified by:
      subSetByKeyRange in interface RowSet
      Parameters:
      startKey - The first key to include in the output.
      endKey - The last key (inclusive) to include in the output.
      Returns:
      A new RowSet, containing only values >= startKey and <= endKey.
    • subSetForPositions

      public final WritableRowSet subSetForPositions(RowSequence posRowSequence, boolean reversed)
      Description copied from interface: RowSet
      Get a subset of this RowSet according to the supplied sequence of row positions in posRowSequence.
      Specified by:
      subSetForPositions in interface RowSet
      Parameters:
      posRowSequence - The RowSequence of positions ranges to get (as in RowSet.get(long))
      reversed - Whether to treat posRowSet as offsets relative to RowSet.size() rather than 0
      Returns:
      A new RowSet, containing the row keys from this RowSet at the row positions in posRowSequence
    • subSetForPositions

      public final WritableRowSet subSetForPositions(RowSequence positions)
      Description copied from interface: RowSet
      Get a subset of this RowSet according to the supplied sequence of row positions in posRowSequence.
      Specified by:
      subSetForPositions in interface RowSet
      Parameters:
      positions - The RowSequence of position-based ranges to extract.
      Returns:
      A new RowSet, containing values at the locations in the provided RowSet.
    • subSetForReversePositions

      public final WritableRowSet subSetForReversePositions(RowSequence positions)
      Description copied from interface: RowSet
      Get a subset of this RowSet according to the supplied sequence of row positions relative to RowSet.size() in posRowSequence.
      Specified by:
      subSetForReversePositions in interface RowSet
      Parameters:
      positions - The RowSequence of positions ranges to get (as in RowSet.get(long))
      Returns:
      A new RowSet, containing the row keys from this RowSet at the row positions in posRowSequence
    • get

      public final long get(long rowPosition)
      Description copied from interface: RowSet
      Returns the row key at the given row position.
      Specified by:
      get in interface RowSet
      Parameters:
      rowPosition - A row position in this RowSet between 0 and size() - 1.
      Returns:
      The row key at the supplied row position
    • getKeysForPositions

      public final void getKeysForPositions(PrimitiveIterator.OfLong positions, LongConsumer outputKeys)
      Description copied from interface: RowSet
      Returns the sequence of (increasing) keys corresponding to the positions provided as input.
      Specified by:
      getKeysForPositions in interface RowSet
      Parameters:
      positions - an iterator providing row positions in increasing order.
      outputKeys - a consumer of corresponding keys for the positions provided as input.
    • find

      public final long find(long key)
      Description copied from interface: RowSet
      Returns the position in [0..(size-1)] where the key is found. If not found, then return (-(position it would be) - 1), a la Array.binarySearch.
      Specified by:
      find in interface RowSet
      Parameters:
      key - the key to search for
      Returns:
      a position from [0..(size-1)] if the key was found. If the key was not found, then (-position - 1) as in Array.binarySearch.
    • iterator

      @NotNull public final RowSet.Iterator iterator()
      Specified by:
      iterator in interface RowSet
    • searchIterator

      public final RowSet.SearchIterator searchIterator()
      Specified by:
      searchIterator in interface RowSet
    • reverseIterator

      public final RowSet.SearchIterator reverseIterator()
      Specified by:
      reverseIterator in interface RowSet
    • rangeIterator

      public final RowSet.RangeIterator rangeIterator()
      Specified by:
      rangeIterator in interface RowSet
    • getAverageRunLengthEstimate

      public final long getAverageRunLengthEstimate()
      Description copied from interface: RowSequence

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

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

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

      Specified by:
      getAverageRunLengthEstimate in interface RowSequence
      Returns:
      An estimate of the average run length in this RowSequence, in [1, size()]
    • containsRange

      public final boolean containsRange(long start, long end)
      Description copied from interface: RowSet
      Queries whether this RowSet contains every element in the range provided.
      Specified by:
      containsRange in interface RowSet
      Parameters:
      start - Start of the range, inclusive.
      end - End of the range, inclusive.
      Returns:
      true if this RowSet contains every element x in start <= x <= end.
    • fillRowKeyChunk

      public final void fillRowKeyChunk(WritableLongChunk<? super OrderedRowKeys> chunkToFill)
      Description copied from interface: RowSequence

      Fill the supplied WritableLongChunk with individual row keys from this RowSequence.

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

      Specified by:
      fillRowKeyChunk in interface RowSequence
      Parameters:
      chunkToFill - A chunk to fill with individual row keys
    • fillRowKeyRangesChunk

      public final void fillRowKeyRangesChunk(WritableLongChunk<OrderedRowKeyRanges> chunkToFill)
      Description copied from interface: RowSequence

      Fill the supplied WritableLongChunk with row key ranges from this RowSequence.

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

      Specified by:
      fillRowKeyRangesChunk in interface RowSequence
      Parameters:
      chunkToFill - A chunk to fill with row key ranges
    • append

      public LogOutput append(LogOutput logOutput)
      Specified by:
      append in interface LogOutputAppendable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(int maxRanges)
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • writeExternal

      public final void writeExternal(@NotNull @NotNull ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(@NotNull @NotNull ObjectInput in) throws IOException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
    • writeImpl

      public void writeImpl(ObjectOutput out) throws IOException
      Debugging tool to serialize the inner set implementation.
      Parameters:
      out - The destination
      Throws:
      IOException
    • addToBuilderFromImpl

      public static void addToBuilderFromImpl(OrderedLongSet.BuilderRandom builder, WritableRowSetImpl rowSet)
    • getInnerSet

      protected static OrderedLongSet getInnerSet(RowSet rowSet)