Class WritableRowSetImpl
- All Implemented Interfaces:
LogOutputAppendable
,RowSequence
,RowSet
,WritableRowSet
,LongSizedDataStructure
,SafeCloseable
,Externalizable
,Serializable
,AutoCloseable
- Direct Known Subclasses:
TrackingWritableRowSetImpl
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.deephaven.engine.rowset.RowSequence
RowSequence.Iterator
Nested classes/interfaces inherited from interface io.deephaven.engine.rowset.RowSet
RowSet.Evaluator<T extends Comparable<T>>, RowSet.Iterator, RowSet.RangeIterator, RowSet.SearchIterator, RowSet.TargetComparator
-
Field Summary
Fields inherited from interface io.deephaven.engine.rowset.RowSequence
NULL_ROW_KEY
Fields inherited from interface io.deephaven.engine.rowset.RowSet
EMPTY_ITERATOR
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addToBuilderFromImpl
(OrderedLongSet.BuilderRandom builder, WritableRowSetImpl rowSet) final RowSet
asRowSet()
Get aRowSet
representation of thisRowSequence
.final void
clear()
void
close()
Free any resources associated with this object.final void
compact()
May reclaim some unused memory.final boolean
containsRange
(long start, long end) Queries whether this RowSet contains every element in the range provided.final WritableRowSet
copy()
Make a newWritableRowSet
with the same row keys asthis
that is safe for further mutation.final boolean
final void
fillRowKeyChunk
(WritableLongChunk<? super OrderedRowKeys> chunkToFill) Fill the suppliedWritableLongChunk
with individual row keys from thisRowSequence
.final void
fillRowKeyRangesChunk
(WritableLongChunk<OrderedRowKeyRanges> chunkToFill) Fill the suppliedWritableLongChunk
with row key ranges from thisRowSequence
.final long
find
(long key) Returns the position in [0..(size-1)] where the key is found.final long
Get the first row key in this RowSet.final boolean
Provide each value contained in this RowSet, in increased sorted order to the consumer.final boolean
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.final long
get
(long rowPosition) Returns the row key at the given row position.final long
Get an estimate of the average (mean) length of runs of adjacent row keys in thisRowSequence
.final OrderedLongSet
protected static OrderedLongSet
getInnerSet
(RowSet rowSet) final void
getKeysForPositions
(PrimitiveIterator.OfLong positions, LongConsumer outputKeys) Returns the sequence of (increasing) keys corresponding to the positions provided as input.final RowSequence
getRowSequenceByKeyRange
(long startRowKeyInclusive, long endRowKeyInclusive) Get an ordered subset of the row keys in thisRowSequence
for a row key range.final RowSequence
getRowSequenceByPosition
(long startPositionInclusive, long length) Get an ordered subset of the row keys in thisRowSequence
for a position range.final RowSequence.Iterator
Get anRowSequence.Iterator
over thisRowSequence
.final void
insert
(long key) Add a single key to this RowSet if it's not already present.final void
insert
(LongChunk<OrderedRowKeys> keys, int offset, int length) Add all of the (ordered) keys in a slice ofkeys
to this RowSet if they are not already present.final void
Add all of the keys inadded
to this RowSet if they are not already present.final void
insertRange
(long startKey, long endKey) Add all keys in a closed range to this RowSet if they are not already present.final void
insertWithShift
(long shiftAmount, RowSet other) For each key in the provided RowSet, shift it by shiftAmount and insert it in the current RowSet.final @NotNull WritableRowSet
Returns a new RowSet representing the intersection of the current RowSet with the input RowSetfinal WritableRowSet
Returns the row positions ofkeys
in the current set as aWritableRowSet
, stopping at maximumPosition.final boolean
isEmpty()
Queries whether this RowSet is empty (i.e.final RowSet.Iterator
iterator()
final long
Get the last row key in thisRowSequence
.final WritableRowSet
Returns a new RowSet representing the keys of the current set not present inside rowSetToRemove.final boolean
Returns true if a RowSet has any overlap.final boolean
overlapsRange
(long start, long end) Returns true if this RowSet has any overlap with the provided range.protected void
protected void
final RowSet.RangeIterator
final long
void
readExternal
(@NotNull ObjectInput in) final void
remove
(long key) Remove a single key from this RowSet if it's present.final void
remove
(LongChunk<OrderedRowKeys> keys, int offset, int length) Remove all of the (ordered) keys in a slice ofkeys
from this RowSet if they are present.final void
Remove all of the keys inremoved
that are present in this RowSet.final void
removeRange
(long start, long end) Remove all keys in a closed range from this RowSet if they are present.void
Reset this WritableRowSetImpl to match another RowSet by updating theinnerSet
.final void
Modifies the RowSet by removing any keys not in the rowSetToIntersect argument.final void
retainRange
(long startRowKey, long endRowKey) Modifies the RowSet by keeping only keys in the interval [startRowKey, endRowKey]final RowSet.SearchIterator
final RowSet.SearchIterator
final WritableRowSet
shift
(long shiftAmount) final void
shiftInPlace
(long shiftAmount) final long
size()
How many keys are in this RowSet.final WritableRowSet
subSetByKeyRange
(long startKey, long endKey) Get a subset of this RowSet within the specified closed range of row keys.final WritableRowSet
subSetByPositionRange
(long startPos, long endPos) Get a subset of this RowSet within the specified half-closed range of row positions.final WritableRowSet
subSetForPositions
(RowSequence positions) Get a subset of this RowSet according to the supplied sequence of row positions inposRowSequence
.final WritableRowSet
subSetForPositions
(RowSequence posRowSequence, boolean reversed) Get a subset of this RowSet according to the supplied sequence of row positions inposRowSequence
.final WritableRowSet
subSetForReversePositions
(RowSequence positions) Get a subset of this RowSet according to the supplied sequence of row positions relative toRowSet.size()
inposRowSequence
.final boolean
Returns true if this RowSet is a (possibly improper) subset of other.toString()
toString
(int maxRanges) Destructively convert this WritableRowSet into aTrackingWritableRowSet
.final WritableRowSet
Returns a new RowSet representing the keys present in both this RowSet and the argument RowSet.final void
Simultaneously adds the keys from the first RowSet and removes the keys from the second one.final void
final void
writeExternal
(@NotNull ObjectOutput out) void
writeImpl
(ObjectOutput out) Debugging tool to serialize the inner set implementation.Methods inherited from class io.deephaven.engine.rowset.impl.RowSequenceAsChunkImpl
asRowKeyChunk, asRowKeyRangesChunk, closeRowSequenceAsChunkImpl, invalidateRowSequenceAsChunkImpl, runsUpperBound
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.deephaven.util.datastructures.LongSizedDataStructure
intSize, intSize
Methods inherited from interface io.deephaven.engine.rowset.RowSequence
asRowKeyChunk, asRowKeyRangesChunk, forAllRowKeyRanges, isContiguous
Methods inherited from interface io.deephaven.engine.rowset.RowSet
forAllRowKeys, invert, isFlat, isNonempty, isTracking, isWritable, toRowKeyArray, toRowKeyArray, validate, writableCast
Methods inherited from interface io.deephaven.engine.rowset.WritableRowSet
extract, trackingCast
-
Constructor Details
-
WritableRowSetImpl
public WritableRowSetImpl() -
WritableRowSetImpl
-
-
Method Details
-
getInnerSet
-
copy
Description copied from interface:RowSet
Make a newWritableRowSet
with the same row keys asthis
that is safe for further mutation. As in other operations that return aWritableRowSet
, the result must beclosed
by the caller when it is no longer needed. The result will never be aTrackingRowSet
; useWritableRowSet.toTracking()
on the result as needed.- Specified by:
copy
in interfaceRowSet
- Returns:
- The copied
WritableRowSet
-
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 interfaceWritableRowSet
- Returns:
- A
TrackingWritableRowSet
constructed from this WritableRowSet, orthis
if already tracking
-
close
@OverridingMethodsMustInvokeSuper public void close()Description copied from interface:RowSequence
Free any resources associated with this object.
Using any
RowSequence
methods afterclose()
is an error and may produce exceptions or undefined results.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceRowSequence
- Specified by:
close
in interfaceRowSet
- Specified by:
close
in interfaceSafeCloseable
- Overrides:
close
in classRowSequenceAsChunkImpl
-
preMutationHook
protected void preMutationHook() -
postMutationHook
protected void postMutationHook() -
resetTo
Reset this WritableRowSetImpl to match another RowSet by updating theinnerSet
. This will internally assignthis.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 interfaceWritableRowSet
- 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 interfaceWritableRowSet
- 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 interfaceWritableRowSet
- Parameters:
startKey
- The first key to addendKey
- The last key to add (inclusive)
-
insert
Description copied from interface:WritableRowSet
Add all of the (ordered) keys in a slice ofkeys
to this RowSet if they are not already present.- Specified by:
insert
in interfaceWritableRowSet
- Parameters:
keys
- TheLongChunk
ofOrderedRowKeys
to insertoffset
- The offset inkeys
to begin inserting keys fromlength
- The number of keys to insert
-
insert
Description copied from interface:WritableRowSet
Add all of the keys inadded
to this RowSet if they are not already present.- Specified by:
insert
in interfaceWritableRowSet
- 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 interfaceWritableRowSet
- 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 interfaceWritableRowSet
- Parameters:
start
- The first key to removeend
- The last key to remove (inclusive)
-
remove
Description copied from interface:WritableRowSet
Remove all of the (ordered) keys in a slice ofkeys
from this RowSet if they are present.- Specified by:
remove
in interfaceWritableRowSet
- Parameters:
keys
- TheLongChunk
ofOrderedRowKeys
to removeoffset
- The offset inkeys
to begin removing keys fromlength
- The number of keys to remove
-
remove
Description copied from interface:WritableRowSet
Remove all of the keys inremoved
that are present in this RowSet.- Specified by:
remove
in interfaceWritableRowSet
- Parameters:
removed
- The RowSet to remove
-
update
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 interfaceWritableRowSet
-
retain
Description copied from interface:WritableRowSet
Modifies the RowSet by removing any keys not in the rowSetToIntersect argument.- Specified by:
retain
in interfaceWritableRowSet
- 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 interfaceWritableRowSet
- 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 interfaceWritableRowSet
-
shiftInPlace
public final void shiftInPlace(long shiftAmount) - Specified by:
shiftInPlace
in interfaceWritableRowSet
-
insertWithShift
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 interfaceWritableRowSet
- 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 interfaceWritableRowSet
-
size
public final long size()Description copied from interface:RowSet
How many keys are in this RowSet.- Specified by:
size
in interfaceLongSizedDataStructure
- Specified by:
size
in interfaceRowSequence
- Specified by:
size
in interfaceRowSet
- 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 interfaceRowSequence
- Specified by:
isEmpty
in interfaceRowSet
- 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 interfaceRowSequence
- Specified by:
firstRowKey
in interfaceRowSet
- 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 thisRowSequence
.- Specified by:
lastRowKey
in interfaceRowSequence
- Specified by:
lastRowKey
in interfaceRowSet
- Specified by:
lastRowKey
in classRowSequenceAsChunkImpl
- Returns:
- The last row key, or
RowSequence.NULL_ROW_KEY
if there is none.
-
rangesCountUpperBound
public final long rangesCountUpperBound()- Specified by:
rangesCountUpperBound
in classRowSequenceAsChunkImpl
-
getRowSequenceIterator
Description copied from interface:RowSequence
Get anRowSequence.Iterator
over thisRowSequence
.- Specified by:
getRowSequenceIterator
in interfaceRowSequence
- Returns:
- A new iterator, positioned at the first row key
-
getRowSequenceByPosition
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 inthis
that lie at positions in the half-open range [startPositionInclusive
,startPositionInclusive + length
). The returned reference is owned by the caller, who should callclose()
when it is done with it.- Specified by:
getRowSequenceByPosition
in interfaceRowSequence
- Parameters:
startPositionInclusive
- The position of the first row key to includelength
- The number of row keys to include- Returns:
- The subset as an
RowSequence
, which may bethis
-
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 inthis
with the row keys in the closed interval [startRowKeyInclusive
,endRowKeyInclusive
]. The returned reference is owned by the caller, who should callclose()
when it is done with it.- Specified by:
getRowSequenceByKeyRange
in interfaceRowSequence
- Parameters:
startRowKeyInclusive
- The minimum row key to includeendRowKeyInclusive
- The maximum row key to include- Returns:
- The subset as an
RowSequence
, which may bethis
-
asRowSet
Description copied from interface:RowSequence
Get aRowSet
representation of thisRowSequence
.- Specified by:
asRowSet
in interfaceRowSequence
- Returns:
- A
RowSet
representation for the same row keys in the same order
-
invert
Description copied from interface:RowSet
Returns the row positions of
keys
in the current set as aWritableRowSet
, 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 interfaceRowSet
- Parameters:
keys
- The keys to find positions formaximumPosition
- The largest position for which we will find a key- Returns:
- A new
WritableRowSet
containing the positions of the keys in this RowSet
-
intersect
Description copied from interface:RowSet
Returns a new RowSet representing the intersection of the current RowSet with the input RowSet -
overlaps
Description copied from interface:RowSet
Returns true if a RowSet has any overlap. -
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 interfaceRowSet
- 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
Description copied from interface:RowSet
Returns true if this RowSet is a (possibly improper) subset of other. -
minus
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. -
union
Description copied from interface:RowSet
Returns a new RowSet representing the keys present in both this RowSet and the argument RowSet. -
shift
-
validate
-
forEachRowKey
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 interfaceRowSequence
- Specified by:
forEachRowKey
in interfaceRowSet
- 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
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 interfaceRowSequence
- Parameters:
larc
- a consumer to feed the individual row key values to.- Returns:
- false if the consumer provided ever returned false, true otherwise.
-
subSetByPositionRange
Description copied from interface:RowSet
Get a subset of this RowSet within the specified half-closed range of row positions.- Specified by:
subSetByPositionRange
in interfaceRowSet
- 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
Description copied from interface:RowSet
Get a subset of this RowSet within the specified closed range of row keys.- Specified by:
subSetByKeyRange
in interfaceRowSet
- 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
Description copied from interface:RowSet
Get a subset of this RowSet according to the supplied sequence of row positions inposRowSequence
.- Specified by:
subSetForPositions
in interfaceRowSet
- Parameters:
posRowSequence
- TheRowSequence
of positions ranges to get (as inRowSet.get(long)
)reversed
- Whether to treatposRowSet
as offsets relative toRowSet.size()
rather than0
- Returns:
- A new RowSet, containing the row keys from this RowSet at the row positions in
posRowSequence
-
subSetForPositions
Description copied from interface:RowSet
Get a subset of this RowSet according to the supplied sequence of row positions inposRowSequence
.- Specified by:
subSetForPositions
in interfaceRowSet
- Parameters:
positions
- TheRowSequence
of position-based ranges to extract.- Returns:
- A new RowSet, containing values at the locations in the provided RowSet.
-
subSetForReversePositions
Description copied from interface:RowSet
Get a subset of this RowSet according to the supplied sequence of row positions relative toRowSet.size()
inposRowSequence
.- Specified by:
subSetForReversePositions
in interfaceRowSet
- Parameters:
positions
- TheRowSequence
of positions ranges to get (as inRowSet.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. -
getKeysForPositions
Description copied from interface:RowSet
Returns the sequence of (increasing) keys corresponding to the positions provided as input.- Specified by:
getKeysForPositions
in interfaceRowSet
- 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. -
iterator
-
searchIterator
- Specified by:
searchIterator
in interfaceRowSet
-
reverseIterator
- Specified by:
reverseIterator
in interfaceRowSet
-
rangeIterator
- Specified by:
rangeIterator
in interfaceRowSet
-
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 interfaceRowSequence
- 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 interfaceRowSet
- 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
Description copied from interface:RowSequence
Fill the supplied
WritableLongChunk
with individual row keys from thisRowSequence
.The chunk's capacity is assumed to be big enough.
- Specified by:
fillRowKeyChunk
in interfaceRowSequence
- Parameters:
chunkToFill
- A chunk to fill with individual row keys
-
fillRowKeyRangesChunk
Description copied from interface:RowSequence
Fill the supplied
WritableLongChunk
with row key ranges from thisRowSequence
.The chunk's capacity is assumed to be big enough.
- Specified by:
fillRowKeyRangesChunk
in interfaceRowSequence
- Parameters:
chunkToFill
- A chunk to fill with row key ranges
-
append
- Specified by:
append
in interfaceLogOutputAppendable
-
toString
-
toString
-
equals
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
-
writeImpl
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
-