diff --git a/engine/rowset/build.gradle b/engine/rowset/build.gradle index ae24b9d782a..98106f51682 100644 --- a/engine/rowset/build.gradle +++ b/engine/rowset/build.gradle @@ -8,7 +8,7 @@ description 'Engine RowSets: Data structures for working with row keys' dependencies { api project(':engine-chunk') api project(':Base') - api libs.trove + implementation libs.trove implementation project(':Container') implementation project(':engine-context') diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowKeyRangeShiftCallback.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowKeyRangeShiftCallback.java new file mode 100644 index 00000000000..32b76b23994 --- /dev/null +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowKeyRangeShiftCallback.java @@ -0,0 +1,20 @@ +// +// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending +// +package io.deephaven.engine.rowset; + +/** + * Functional interface to pass to {@link RowSetShiftData#apply(RowKeyRangeShiftCallback)} or + * {@link RowSetShiftData#unapply(RowKeyRangeShiftCallback)} to get information about each shift recorded. + */ +@FunctionalInterface +public interface RowKeyRangeShiftCallback { + /** + * Process the shift. + * + * @param beginRange start of range (inclusive) + * @param endRange end of range (inclusive) + * @param shiftDelta amount range has moved by + */ + void shift(long beginRange, long endRange, long shiftDelta); +} diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSet.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSet.java index 1859a0f8c69..20eb6a7c3fc 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSet.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSet.java @@ -3,7 +3,6 @@ // package io.deephaven.engine.rowset; -import gnu.trove.list.array.TLongArrayList; import io.deephaven.base.log.LogOutputAppendable; import io.deephaven.util.SafeCloseable; import io.deephaven.util.datastructures.LongAbortableConsumer; @@ -116,15 +115,6 @@ default WritableRowSet invert(RowSet keys) { */ WritableRowSet invert(RowSet keys, long maximumPosition); - /** - * For the given keys RowSet, under the assertion that none of them are present in the current RowSet, return the - * tentative insertion points in the current RowSet with the count for each of them - * - * @param keys the keys to identify insertion locations - * @return two TLongArrayLists; [0] contains the positions, [1] contains the counts. - */ - TLongArrayList[] findMissing(RowSet keys); - /** * Returns a new RowSet representing the intersection of the current RowSet with the input RowSet */ diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetBuilderSequential.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetBuilderSequential.java index e678a514e51..aad8cad51ba 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetBuilderSequential.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetBuilderSequential.java @@ -3,7 +3,6 @@ // package io.deephaven.engine.rowset; -import gnu.trove.procedure.TLongProcedure; import io.deephaven.engine.rowset.chunkattributes.OrderedRowKeyRanges; import io.deephaven.engine.rowset.chunkattributes.OrderedRowKeys; import io.deephaven.util.datastructures.LongRangeConsumer; @@ -17,7 +16,7 @@ /** * Builder interface for {@link RowSet} construction in strict sequential order. */ -public interface RowSetBuilderSequential extends TLongProcedure, LongRangeConsumer { +public interface RowSetBuilderSequential extends LongRangeConsumer { /** * Hint to call, but if called, (a) should be called before providing any values, and (b) no value should be @@ -61,12 +60,6 @@ default void appendOrderedRowKeyRangesChunk(final LongChunk appendRanges(new LongChunkRangeIterator(chunk)); } - @Override - default boolean execute(final long value) { - appendKey(value); - return true; - } - /** * Appends a {@link RowSequence} to this builder. * diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetFactory.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetFactory.java index 78c620c661b..a6b7d6dd91e 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetFactory.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetFactory.java @@ -3,12 +3,10 @@ // package io.deephaven.engine.rowset; -import gnu.trove.list.TLongList; import io.deephaven.engine.rowset.impl.AdaptiveRowSetBuilderRandom; import io.deephaven.engine.rowset.impl.BasicRowSetBuilderSequential; import io.deephaven.engine.rowset.impl.WritableRowSetImpl; import io.deephaven.engine.rowset.impl.singlerange.SingleRange; -import org.jetbrains.annotations.NotNull; /** * Repository of factory methods for constructing {@link WritableRowSet row sets}. @@ -56,21 +54,6 @@ public static WritableRowSet fromKeys(final long rowKey) { return fromRange(rowKey, rowKey); } - /** - * Get a {@link WritableRowSet} containing the specified row keys. - *

- * The provided {@link TLongList} is sorted and then passed to a {@link RowSetBuilderSequential}. - * - * @param rowKeys A {@link TLongList}. Note that this list is mutated within the method! - * @return A new {@link WritableRowSet} containing the values from {@code rowKeys} - */ - public static RowSet fromKeys(@NotNull final TLongList rowKeys) { - rowKeys.sort(); - final RowSetBuilderSequential builder = builderSequential(); - rowKeys.forEach(builder); - return builder.build(); - } - /** * Create a {@link WritableRowSet} containing the continuous range [firstRowKey, lastRowKey]. * diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftCallback.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftCallback.java new file mode 100644 index 00000000000..08e0c7685b3 --- /dev/null +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftCallback.java @@ -0,0 +1,17 @@ +// +// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending +// +package io.deephaven.engine.rowset; + +/** + * Callback interface for propagating shifts over entire {@link RowSet RowSets}. + */ +public interface RowSetShiftCallback { + /** + * Signals that the row keys in {@code rowSet} should be shifted by the provided {@code shiftDelta}. + * + * @param rowSet The row keys to shift + * @param shiftDelta The shift delta to apply to each row key in {@code rowSet} + */ + void shift(RowSet rowSet, long shiftDelta); +} diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftData.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftData.java index 9e1c20247b1..8db68e8e0fe 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftData.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSetShiftData.java @@ -18,10 +18,11 @@ import java.io.Serializable; /** - * A set of sorted shifts. To apply shifts without losing data, use {@link RowSetShiftData#apply(Callback)}. The - * callback will be invoked with shifts in an order that will preserve data when applied immediately using memmove - * semantics. Internally the shifts are ordered by rangeStart. The {@link RowSetShiftData.Builder} will verify that no - * two ranges overlap before or after shifting and assert that the constructed {@code RowSetShiftData} will be valid. + * A set of sorted shifts. To apply shifts without losing data, use + * {@link RowSetShiftData#apply(RowKeyRangeShiftCallback)}. The callback will be invoked with shifts in an order that + * will preserve data when applied immediately using memmove semantics. Internally the shifts are ordered by rangeStart. + * The {@link RowSetShiftData.Builder} will verify that no two ranges overlap before or after shifting and assert that + * the constructed {@code RowSetShiftData} will be valid. */ public final class RowSetShiftData implements Serializable, LogOutputAppendable { @@ -224,18 +225,6 @@ public boolean equals(final Object obj) { */ public static final RowSetShiftData EMPTY = new RowSetShiftData(); - @FunctionalInterface - public interface Callback { - /** - * Process the shift. - * - * @param beginRange start of range (inclusive) - * @param endRange end of range (inclusive) - * @param shiftDelta amount range has moved by - */ - void shift(long beginRange, long endRange, long shiftDelta); - } - /** * Apply all shifts in a memmove-semantics-safe ordering through the provided {@code shiftCallback}. *

@@ -243,7 +232,7 @@ public interface Callback { * * @param shiftCallback the callback that will process all shifts */ - public void apply(final Callback shiftCallback) { + public void apply(final RowKeyRangeShiftCallback shiftCallback) { final int polaritySwapSize = polaritySwapIndices.size(); for (int idx = 0; idx < polaritySwapSize; ++idx) { int start = (idx == 0) ? 0 : polaritySwapIndices.get(idx - 1); @@ -267,7 +256,7 @@ public void apply(final Callback shiftCallback) { * * @param shiftCallback the callback that will process all reverse shifts */ - public void unapply(final Callback shiftCallback) { + public void unapply(final RowKeyRangeShiftCallback shiftCallback) { final int polaritySwapSize = polaritySwapIndices.size(); for (int idx = 0; idx < polaritySwapSize; ++idx) { int start = (idx == 0) ? 0 : polaritySwapIndices.get(idx - 1); diff --git a/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/WritableRowSetImpl.java b/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/WritableRowSetImpl.java index 1d4ced7aae8..487d9bae220 100644 --- a/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/WritableRowSetImpl.java +++ b/engine/rowset/src/main/java/io/deephaven/engine/rowset/impl/WritableRowSetImpl.java @@ -3,7 +3,6 @@ // package io.deephaven.engine.rowset.impl; -import gnu.trove.list.array.TLongArrayList; import io.deephaven.base.log.LogOutput; import io.deephaven.base.verify.Assert; import io.deephaven.engine.rowset.*; @@ -260,11 +259,6 @@ public final WritableRowSet invert(final RowSet keys, final long maximumPosition return new WritableRowSetImpl(innerSet.ixInvertOnNew(getInnerSet(keys), maximumPosition)); } - @Override - public final TLongArrayList[] findMissing(final RowSet keys) { - return RowSetUtils.findMissing(this, keys); - } - @NotNull @Override public final WritableRowSet intersect(@NotNull final RowSet range) { diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/TableUpdateValidator.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/TableUpdateValidator.java index c09fa9ce61d..b4f9b7e817b 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/TableUpdateValidator.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/TableUpdateValidator.java @@ -10,14 +10,14 @@ import io.deephaven.chunk.attributes.Values; import io.deephaven.chunk.util.hashing.ChunkEquals; import io.deephaven.configuration.Configuration; +import io.deephaven.engine.rowset.RowKeyRangeShiftCallback; import io.deephaven.engine.rowset.RowSequence; import io.deephaven.engine.rowset.RowSet; -import io.deephaven.engine.rowset.RowSetShiftData; import io.deephaven.engine.rowset.TrackingWritableRowSet; import io.deephaven.engine.table.*; import io.deephaven.engine.table.impl.sources.SparseArrayColumnSource; import io.deephaven.engine.table.impl.util.ChunkUtils; -import io.deephaven.engine.table.impl.util.ShiftData; +import io.deephaven.engine.rowset.RowSetShiftCallback; import io.deephaven.util.SafeCloseable; import io.deephaven.util.SafeCloseableList; import io.deephaven.vector.*; @@ -325,7 +325,7 @@ public void dontValidateColumns(String[] columnNames) { columnInfos = ciBuilder.toArray(new ColumnInfo[0]); } - private class ColumnInfo implements RowSetShiftData.Callback, SafeCloseable { + private class ColumnInfo implements RowKeyRangeShiftCallback, SafeCloseable { final String name; final boolean isPrimitive; final ModifiedColumnSet modifiedColumnSet; @@ -351,7 +351,7 @@ private ColumnInfo(QueryTable tableToValidate, String columnName) { this.isPrimitive = source.getType().isPrimitive(); this.expectedSource = SparseArrayColumnSource.getSparseMemoryColumnSource(source.getType(), source.getComponentType()); - Assert.eqTrue(this.expectedSource instanceof ShiftData.RowSetShiftCallback, + Assert.eqTrue(this.expectedSource instanceof RowSetShiftCallback, "expectedSource instanceof ShiftData.RowSetShiftCallback"); this.chunkEquals = ChunkEquals.makeEqual(source.getChunkType()); @@ -401,8 +401,7 @@ private WritableBooleanChunk equalValuesDest() { @Override public void shift(final long beginRange, final long endRange, final long shiftDelta) { - ((ShiftData.RowSetShiftCallback) expectedSource).shift( - rowSet.subSetByKeyRange(beginRange, endRange), shiftDelta); + ((RowSetShiftCallback) expectedSource).shift(rowSet.subSetByKeyRange(beginRange, endRange), shiftDelta); } public void remove(final RowSet toRemove) { diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ArrayBackedColumnSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ArrayBackedColumnSource.java index 0d5fda89395..090cb61677c 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ArrayBackedColumnSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ArrayBackedColumnSource.java @@ -14,7 +14,6 @@ import io.deephaven.chunk.attributes.Values; import io.deephaven.engine.rowset.RowSequence; import io.deephaven.engine.rowset.RowSequenceFactory; -import io.deephaven.engine.table.impl.util.ShiftData; import io.deephaven.qst.array.Array; import io.deephaven.qst.array.BooleanArray; import io.deephaven.qst.array.ByteArray; @@ -47,7 +46,7 @@ */ public abstract class ArrayBackedColumnSource extends AbstractColumnSource - implements FillUnordered, ShiftData.ShiftCallback, WritableColumnSource, InMemoryColumnSource, + implements FillUnordered, WritableColumnSource, InMemoryColumnSource, ChunkedBackingStoreExposedWritableSource { static final int DEFAULT_RECYCLER_CAPACITY = 1024; @@ -426,20 +425,6 @@ public static WritableColumnSource getMemoryColumnSource(final long size, @Override public abstract void ensureCapacity(long size, boolean nullFill); - @Override - public void shift(final long start, final long end, final long offset) { - if (offset > 0) { - for (long i = end; i >= start; i--) { - set((i + offset), get(i)); - } - } else { - for (long i = start; i <= end; i++) { - set((i + offset), get(i)); - } - } - - } - /** * Creates an in-memory ColumnSource from the supplied dataArray, using instanceof checks to determine the * appropriate type of column source to produce. diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/BooleanArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/BooleanArraySource.java index f7a5760fe24..72e41f33e71 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/BooleanArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/BooleanArraySource.java @@ -196,19 +196,6 @@ public Boolean getPrev(long rowKey) { return BooleanUtils.byteAsBoolean(getPrevByte(rowKey)); } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getByte(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getByte(i)); - } - } - } - @Override byte[] allocateNullFilledBlock(int size) { final byte[] result = new byte[size]; diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ByteArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ByteArraySource.java index 76693de2f90..03a29432654 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ByteArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ByteArraySource.java @@ -193,19 +193,6 @@ public final byte getPrevByte(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getByte(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getByte(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/CharacterArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/CharacterArraySource.java index 088cc63a4ef..fbbc84ed6dc 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/CharacterArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/CharacterArraySource.java @@ -190,19 +190,6 @@ public final char getPrevChar(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getChar(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getChar(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/DoubleArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/DoubleArraySource.java index 2343325982d..74a523a1e73 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/DoubleArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/DoubleArraySource.java @@ -193,19 +193,6 @@ public final double getPrevDouble(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getDouble(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getDouble(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/FloatArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/FloatArraySource.java index bd01ec0ee0e..5579e8d2159 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/FloatArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/FloatArraySource.java @@ -193,19 +193,6 @@ public final float getPrevFloat(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getFloat(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getFloat(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/IntegerArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/IntegerArraySource.java index b4172cc7794..07a4f676c33 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/IntegerArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/IntegerArraySource.java @@ -193,19 +193,6 @@ public final int getPrevInt(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getInt(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getInt(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/LongArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/LongArraySource.java index 2cbb16cd130..5296629e4d0 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/LongArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/LongArraySource.java @@ -216,19 +216,6 @@ public final long getPrevLong(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getLong(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getLong(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeArraySource.java index 0d91720ef27..e351b8da09f 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeArraySource.java @@ -16,13 +16,12 @@ import io.deephaven.engine.table.WritableColumnSource; import io.deephaven.engine.table.WritableSourceWithPrepareForParallelPopulation; import io.deephaven.engine.table.impl.AbstractColumnSource; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import java.time.*; public abstract class NanosBasedTimeArraySource extends AbstractColumnSource - implements FillUnordered, ShiftData.ShiftCallback, WritableColumnSource, + implements FillUnordered, WritableColumnSource, InMemoryColumnSource, WritableSourceWithPrepareForParallelPopulation, ConvertibleTimeSource { protected final LongArraySource nanoSource; @@ -79,11 +78,6 @@ public long getPrevLong(long rowKey) { public final long getAndSetUnsafe(long rowKey, long newValue) { return nanoSource.getAndSetUnsafe(rowKey, newValue); } - - @Override - public void shift(long start, long end, long offset) { - nanoSource.shift(start, end, offset); - } // endregion // region ArraySource impl diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeSparseArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeSparseArraySource.java index 02abc54a547..30d4e490a9b 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeSparseArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NanosBasedTimeSparseArraySource.java @@ -16,7 +16,7 @@ import io.deephaven.engine.table.WritableColumnSource; import io.deephaven.engine.table.WritableSourceWithPrepareForParallelPopulation; import io.deephaven.engine.table.impl.AbstractColumnSource; -import io.deephaven.engine.table.impl.util.ShiftData; +import io.deephaven.engine.rowset.RowSetShiftCallback; import org.jetbrains.annotations.NotNull; import java.time.Instant; @@ -30,7 +30,7 @@ */ public abstract class NanosBasedTimeSparseArraySource extends AbstractColumnSource implements FillUnordered, WritableColumnSource, InMemoryColumnSource, - PossiblyImmutableColumnSource, WritableSourceWithPrepareForParallelPopulation, ShiftData.RowSetShiftCallback, + PossiblyImmutableColumnSource, WritableSourceWithPrepareForParallelPopulation, RowSetShiftCallback, ConvertibleTimeSource { protected final LongSparseArraySource nanoSource; diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NullValueColumnSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NullValueColumnSource.java index aec4b545db7..2c2e873e58d 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NullValueColumnSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/NullValueColumnSource.java @@ -18,7 +18,6 @@ import io.deephaven.hash.KeyedObjectHashMap; import io.deephaven.hash.KeyedObjectKey; import io.deephaven.chunk.WritableChunk; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,7 +36,7 @@ * A column source that returns null for all keys. Trivially "writable" since it can only contain null values. */ public final class NullValueColumnSource extends AbstractColumnSource - implements ShiftData.ShiftCallback, InMemoryColumnSource, RowKeyAgnosticChunkSource, + implements InMemoryColumnSource, RowKeyAgnosticChunkSource, WritableColumnSource { private static final KeyedObjectKey.Basic, Class>, NullValueColumnSource> KEY_TYPE = @@ -167,9 +166,6 @@ public short getPrevShort(long rowKey) { return NULL_SHORT; } - @Override - public void shift(long start, long end, long offset) {} - @Override public boolean isImmutable() { return true; diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ShortArraySource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ShortArraySource.java index 928b9ec20bf..6ac23b0db31 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ShortArraySource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/ShortArraySource.java @@ -193,19 +193,6 @@ public final short getPrevShort(long rowKey) { } } - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (long i = (int) end; i >= start; i--) { - set((i + offset), getShort(i)); - } - } else { - for (int i = (int) start; i <= end; i++) { - set((i + offset), getShort(i)); - } - } - } - public void move(long source, long dest, long length) { if (prevBlocks != null) { throw new UnsupportedOperationException(); diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SingleValueColumnSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SingleValueColumnSource.java index dadb09f9be4..bf343470884 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SingleValueColumnSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SingleValueColumnSource.java @@ -8,12 +8,9 @@ import io.deephaven.engine.table.ChunkSink; import io.deephaven.engine.table.WritableColumnSource; import io.deephaven.engine.table.impl.AbstractColumnSource; -import io.deephaven.engine.table.impl.util.ShiftData; - -import static io.deephaven.util.QueryConstants.NULL_BYTE; public abstract class SingleValueColumnSource extends AbstractColumnSource - implements WritableColumnSource, ChunkSink, ShiftData.ShiftCallback, InMemoryColumnSource, + implements WritableColumnSource, ChunkSink, InMemoryColumnSource, RowKeyAgnosticChunkSource { protected transient long changeTime; @@ -28,9 +25,6 @@ public final void startTrackingPrevValues() { isTrackingPrevValues = true; } - @Override - public void shift(long start, long end, long offset) {} - public static SingleValueColumnSource getSingleValueColumnSource(Class type) { SingleValueColumnSource result; if (type == Byte.class || type == byte.class) { diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SparseArrayColumnSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SparseArrayColumnSource.java index d67858056f9..2394e07c17e 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SparseArrayColumnSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/SparseArrayColumnSource.java @@ -8,7 +8,7 @@ import io.deephaven.engine.table.WritableColumnSource; import io.deephaven.engine.table.WritableSourceWithPrepareForParallelPopulation; import io.deephaven.engine.table.impl.AbstractColumnSource; -import io.deephaven.engine.table.impl.util.ShiftData; +import io.deephaven.engine.rowset.RowSetShiftCallback; import io.deephaven.util.type.ArrayTypeUtils; import io.deephaven.engine.rowset.chunkattributes.RowKeys; import io.deephaven.chunk.attributes.Values; @@ -74,7 +74,7 @@ public abstract class SparseArrayColumnSource extends AbstractColumnSource implements FillUnordered, WritableColumnSource, InMemoryColumnSource, PossiblyImmutableColumnSource, - WritableSourceWithPrepareForParallelPopulation, ShiftData.RowSetShiftCallback { + WritableSourceWithPrepareForParallelPopulation, RowSetShiftCallback { static final int DEFAULT_RECYCLER_CAPACITY = 1024; diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantByteSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantByteSource.java index 6e8b5e8a813..05475da83ae 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantByteSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantByteSource.java @@ -18,7 +18,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -32,7 +31,7 @@ */ public class ImmutableConstantByteSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForByte, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForByte, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final byte value; @@ -70,9 +69,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantCharSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantCharSource.java index 0788b2cb9c3..9ea61d9946d 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantCharSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantCharSource.java @@ -12,7 +12,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -26,7 +25,7 @@ */ public class ImmutableConstantCharSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForChar, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForChar, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final char value; @@ -64,9 +63,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantDoubleSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantDoubleSource.java index c75d5f2faba..75c3dd0b441 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantDoubleSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantDoubleSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -30,7 +29,7 @@ */ public class ImmutableConstantDoubleSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForDouble, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForDouble, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final double value; @@ -68,9 +67,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantFloatSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantFloatSource.java index 81e961dbfec..9b895d41bdd 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantFloatSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantFloatSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -30,7 +29,7 @@ */ public class ImmutableConstantFloatSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForFloat, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForFloat, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final float value; @@ -68,9 +67,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantIntSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantIntSource.java index ea4a6a8a82c..e9fd8c3938c 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantIntSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantIntSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -30,7 +29,7 @@ */ public class ImmutableConstantIntSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForInt, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForInt, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final int value; @@ -68,9 +67,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantLongSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantLongSource.java index 7d9e322f6d3..14c235bd509 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantLongSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantLongSource.java @@ -25,7 +25,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -39,7 +38,7 @@ */ public class ImmutableConstantLongSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForLong, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForLong, InMemoryColumnSource, RowKeyAgnosticChunkSource , ConvertibleTimeSource { private final long value; @@ -77,9 +76,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantNanosBasedTimeSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantNanosBasedTimeSource.java index 075b786b412..bf55d4f5fde 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantNanosBasedTimeSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantNanosBasedTimeSource.java @@ -13,7 +13,6 @@ import io.deephaven.engine.table.ColumnSource; import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import java.time.Instant; @@ -23,7 +22,7 @@ import java.time.ZonedDateTime; public abstract class ImmutableConstantNanosBasedTimeSource extends AbstractColumnSource - implements ShiftData.ShiftCallback, InMemoryColumnSource, RowKeyAgnosticChunkSource, + implements InMemoryColumnSource, RowKeyAgnosticChunkSource, ConvertibleTimeSource { protected final ImmutableConstantLongSource nanoSource; @@ -61,9 +60,6 @@ public long getLong(long rowKey) { public long getPrevLong(long rowKey) { return nanoSource.getPrevLong(rowKey); } - - @Override - public final void shift(final long start, final long end, final long offset) {} // endregion // region Chunking diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantObjectSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantObjectSource.java index 5971e14e61f..952559d98fd 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantObjectSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantObjectSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -29,7 +28,7 @@ */ public class ImmutableConstantObjectSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForObject, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForObject, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final T value; @@ -67,9 +66,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantShortSource.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantShortSource.java index cdf53c08c05..95eb2ea4989 100644 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantShortSource.java +++ b/engine/table/src/main/java/io/deephaven/engine/table/impl/sources/immutable/ImmutableConstantShortSource.java @@ -16,7 +16,6 @@ import io.deephaven.engine.table.impl.AbstractColumnSource; import io.deephaven.engine.table.impl.ImmutableColumnSourceGetDefaults; import io.deephaven.engine.table.impl.sources.*; -import io.deephaven.engine.table.impl.util.ShiftData; import org.jetbrains.annotations.NotNull; import static io.deephaven.engine.rowset.RowSequence.NULL_ROW_KEY; @@ -30,7 +29,7 @@ */ public class ImmutableConstantShortSource extends AbstractColumnSource - implements ImmutableColumnSourceGetDefaults.ForShort, ShiftData.ShiftCallback, InMemoryColumnSource, + implements ImmutableColumnSourceGetDefaults.ForShort, InMemoryColumnSource, RowKeyAgnosticChunkSource /* MIXIN_IMPLS */ { private final short value; @@ -68,9 +67,6 @@ public final void fillPrevChunk( fillChunk(context, destination, rowSequence); } - @Override - public final void shift(final long start, final long end, final long offset) {} - @Override public void fillChunkUnordered( @NotNull FillContext context, diff --git a/engine/table/src/main/java/io/deephaven/engine/table/impl/util/ShiftData.java b/engine/table/src/main/java/io/deephaven/engine/table/impl/util/ShiftData.java deleted file mode 100644 index 1e3f9859561..00000000000 --- a/engine/table/src/main/java/io/deephaven/engine/table/impl/util/ShiftData.java +++ /dev/null @@ -1,142 +0,0 @@ -// -// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending -// -package io.deephaven.engine.table.impl.util; - -import gnu.trove.list.TLongList; -import gnu.trove.list.array.TLongArrayList; -import io.deephaven.engine.rowset.RowSet; - -public class ShiftData { - - private final TLongArrayList startIndex; - private final TLongArrayList endIndex; - private final TLongArrayList offsets; - private final int size; - private int runningSize = 0; - private long runningOffset = 0; - - public RowSet getAddedPos() { - return addedPos; - } - - private RowSet addedPos; - - public ShiftData(RowSet rowSet, RowSet removed, RowSet added) { - TLongList[] removedKeys = rowSet.findMissing(removed); - addedPos = rowSet.invert(added); - endIndex = new TLongArrayList(); - startIndex = new TLongArrayList(); - offsets = new TLongArrayList(); - int removedIndex = 0; - TLongList removedPositions = removedKeys[0]; - TLongList removedCount = removedKeys[1]; - for (RowSet.RangeIterator addedIt = addedPos.rangeIterator(); addedIt.hasNext();) { - addedIt.next(); - int startOffset = (int) addedIt.currentRangeStart(); - int endOffset = (int) addedIt.currentRangeEnd(); - while (removedIndex < removedPositions.size() && removedPositions.get(removedIndex) < startOffset) { - removeRange(removedPositions.get(removedIndex), removedCount.get(removedIndex)); - removedIndex++; - } - int deleteCount = 0; - while (removedIndex < removedPositions.size() && removedPositions.get(removedIndex) <= endOffset) { - deleteCount += removedCount.get(removedIndex); - removedIndex++; - } - addRange(startOffset, endOffset, deleteCount); - } - while (removedIndex < removedPositions.size()) { - removeRange(removedPositions.get(removedIndex), removedCount.get(removedIndex)); - removedIndex++; - } - if (runningSize > 0) { - if (startIndex.get(runningSize - 1) <= (rowSet.size() - added.size() + removed.size() - 1)) { - endIndex.set(runningSize - 1, (int) (rowSet.size() - added.size() + removed.size() - 1)); - } else { - runningSize--; - } - } - size = runningSize; - } - - void addRange(long firstIndex, long lastIndex, long deletionCount) { - if (lastIndex - firstIndex + 1 == deletionCount) { - return; - } - if (runningSize > 0) { - endIndex.set(runningSize - 1, firstIndex - runningOffset - 1); - } - - - long newStartIndex = firstIndex + deletionCount - runningOffset; - runningOffset = lastIndex + runningOffset + 1 - (deletionCount + firstIndex); - - if (runningSize > 0 && ((newStartIndex + runningOffset) == (startIndex.get(runningSize - 1) - + offsets.get(runningSize - 1)))) { - startIndex.set(runningSize - 1, newStartIndex); - offsets.set(runningSize - 1, runningOffset); - } else { - startIndex.add(newStartIndex); - offsets.add(runningOffset); - endIndex.add(0); - runningSize++; - } - } - - void removeRange(long firstIndex, long count) { - if (runningSize > 0) { - endIndex.set(runningSize - 1, firstIndex - runningOffset - 1); - } - - long newStartIndex = firstIndex - runningOffset + count; - runningOffset = runningOffset - count; - - if (runningSize > 0 - && (newStartIndex + runningOffset == startIndex.get(runningSize - 1) + offsets.get(runningSize - 1))) { - startIndex.set(runningSize - 1, newStartIndex); - offsets.set(runningSize - 1, runningOffset); - } else { - startIndex.add(newStartIndex); - offsets.add(runningOffset); - endIndex.add(0); - runningSize++; - } - } - - public interface ShiftCallback { - void shift(long start, long end, long offset); - } - - public interface RowSetShiftCallback { - void shift(RowSet rowSet, long offset); - } - - public void applyDataShift(ShiftCallback shiftCallback) { - int startPos = 0; - int currentPos = 0; - while (currentPos < size) { - if (offsets.get(startPos) > 0) { - while (currentPos < size && offsets.get(currentPos) > 0) { - currentPos++; - } - for (int ii = currentPos - 1; ii >= startPos; ii--) { - shiftCallback.shift(startIndex.get(ii), endIndex.get(ii), offsets.get(ii)); - } - } else if (offsets.get(startPos) < 0) { - while (currentPos < size && offsets.get(currentPos) < 0) { - currentPos++; - } - for (int ii = startPos; ii < currentPos; ii++) { - shiftCallback.shift(startIndex.get(ii), endIndex.get(ii), offsets.get(ii)); - } - } else { - while (currentPos < size && offsets.get(currentPos) == 0) { - currentPos++; - } - } - startPos = currentPos; - } - } - -} diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/RowSetShiftDataTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/util/RowSetShiftDataTest.java index 97ec38f5cea..2e8e68934a8 100644 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/RowSetShiftDataTest.java +++ b/engine/table/src/test/java/io/deephaven/engine/table/impl/util/RowSetShiftDataTest.java @@ -458,7 +458,7 @@ private long[] fromValues(long... values) { return values; } - private RowSetShiftData.Callback createMemMovCallback(final long[] arr) { + private RowKeyRangeShiftCallback createMemMovCallback(final long[] arr) { return (start, end, delta) -> { final long dir = (delta > 0) ? -1 : 1; if (dir < 0) { diff --git a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/ShiftDataTest.java b/engine/table/src/test/java/io/deephaven/engine/table/impl/util/ShiftDataTest.java deleted file mode 100644 index 1e3573b9567..00000000000 --- a/engine/table/src/test/java/io/deephaven/engine/table/impl/util/ShiftDataTest.java +++ /dev/null @@ -1,271 +0,0 @@ -// -// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending -// -package io.deephaven.engine.table.impl.util; - -import io.deephaven.engine.rowset.RowSet; -import io.deephaven.engine.rowset.RowSetBuilderRandom; -import io.deephaven.engine.rowset.RowSetBuilderSequential; -import io.deephaven.engine.rowset.RowSetFactory; -import junit.framework.TestCase; - -import java.util.*; - -public class ShiftDataTest extends TestCase { - - public void testSystematic() { - RowSet rowSet = getSortedIndex(); - RowSet removed = getSortedIndex(); - RowSet added = getSortedIndex(); - ShiftData shiftData = new ShiftData(rowSet, removed, added); - shiftData.applyDataShift(new ShiftData.ShiftCallback() { - @Override - public void shift(long start, long end, long offset) { - assertTrue("Should not call it", false); - } - }); - rowSet = getSortedIndex(1L); - testNoNotification(rowSet, removed, added); - added = getSortedIndex(1L); - testNoNotification(rowSet, removed, added); - rowSet = getSortedIndex(1L, 2); - added = getSortedIndex(1L, 2); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(1L, 2, 3); - added = getSortedIndex(2, 3); - testNoNotification(rowSet, removed, added); - - removed = getSortedIndex(4, 5); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(); - added = getSortedIndex(); - removed = getSortedIndex(4, 5); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(1L, 2, 4); - added = getSortedIndex(2); - removed = getSortedIndex(3); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(1L, 3, 4); - added = getSortedIndex(3); - removed = getSortedIndex(2); - testNoNotification(rowSet, removed, added); - - rowSet = getSortedIndex(); - added = getSortedIndex(); - removed = getSortedIndex(1, 2, 4); - testNoNotification(rowSet, removed, added); - - - rowSet = getSortedIndex(4); - added = getSortedIndex(); - removed = getSortedIndex(1); - checkExpectations(rowSet, removed, added, new long[][] {{1, 1, -1}}); - - rowSet = getSortedIndex(4, 5); - added = getSortedIndex(4); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{0, 0, 1}}); - - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(4); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{0, 2, 1}}); - - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(4, 5); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{0, 1, 2}}); - - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(5, 6); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{1, 1, 2}}); - // was 1,4,7 - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(5, 6); - removed = getSortedIndex(1); - checkExpectations(rowSet, removed, added, new long[][] {{1, 1, -1}, {2, 2, 1}}); - - // was 1,2,4,6,7 - rowSet = getSortedIndex(4, 5, 6, 7); - added = getSortedIndex(5); - removed = getSortedIndex(1, 2); - checkExpectations(rowSet, removed, added, new long[][] {{2, 2, -2}, {3, 4, -1}}); - - // was 6,7,9,11 - rowSet = getSortedIndex(4, 5, 9, 10, 11); - added = getSortedIndex(4, 5, 10); - removed = getSortedIndex(6, 7); - checkExpectations(rowSet, removed, added, new long[][] {{3, 3, 1}}); - - // was 6,7,9,11 - rowSet = getSortedIndex(4, 9, 10, 11); - added = getSortedIndex(4, 10); - removed = getSortedIndex(6, 7); - checkExpectations(rowSet, removed, added, new long[][] {{2, 2, -1}}); - - // was 2,4,6,8 - rowSet = getSortedIndex(1, 2, 3, 4, 5, 6, 7, 8); - added = getSortedIndex(1, 3, 5, 7); - removed = getSortedIndex(); - checkExpectations(rowSet, removed, added, new long[][] {{3, 3, 4}, {2, 2, 3}, {1, 1, 2}, {0, 0, 1}}); - - // was 2,4,6,8,10,12,16 - rowSet = getSortedIndex(1, 2, 3, 4, 8, 16); - added = getSortedIndex(1, 3); - removed = getSortedIndex(6, 10, 12); - checkExpectations(rowSet, removed, added, new long[][] {{3, 3, 1}, {1, 1, 2}, {0, 0, 1}, {6, 6, -1}}); - - // was 100,200,300,400,500,600,700 - rowSet = getSortedIndex(100, 200, 230, 240, 250, 260, 270, 500, 550, 700); - added = getSortedIndex(230, 240, 250, 260, 270, 550); - removed = getSortedIndex(300, 400, 600); - checkExpectations(rowSet, removed, added, new long[][] {{6, 6, 3}, {4, 4, 3}}); - } - - private void checkExpectations(RowSet rowSet, RowSet removed, RowSet added, long[][] expected) { - ShiftData shiftData; - class Expectations implements ShiftData.ShiftCallback { - - private final long[][] expected; - private int i = 0; - - Expectations(long[][] expected) { - this.expected = expected; - } - - @Override - public void shift(long start, long end, long offset) { - long[] current = expected[i++]; - assertEquals(current[0], start); - assertEquals(current[1], end); - assertEquals(current[2], offset); - } - - public void allMet() { - assertEquals(i, expected.length); - } - } - shiftData = new ShiftData(rowSet, removed, added); - final Expectations expectations = new Expectations(expected); - shiftData.applyDataShift(expectations); - expectations.allMet(); - } - - private void testNoNotification(RowSet rowSet, RowSet removed, RowSet added) { - ShiftData shiftData; - shiftData = new ShiftData(rowSet, removed, added); - shiftData.applyDataShift(new ShiftData.ShiftCallback() { - @Override - public void shift(long start, long end, long offset) { - assertTrue("Should not call it", false); - } - }); - } - - Random random = new Random(123); - - public void testRandom() { - for (int k = 0; k < 100; k++) { - RowSet initialRowSet = getBaseIndex(100, 10); - RowSet added = getRandomIndex(20, 1, 10); - RowSet removed = getRandomRemoves(initialRowSet, 2); - RowSet finalRowSet = getFinalIndex(initialRowSet, added, removed); - final long resultKeys[] = new long[(int) Math.max(initialRowSet.size(), finalRowSet.size())]; - int pos = 0; - for (RowSet.Iterator it = initialRowSet.iterator(); it.hasNext();) { - resultKeys[pos++] = it.nextLong(); - } - ShiftData shiftData = new ShiftData(finalRowSet, removed, added); - shiftData.applyDataShift(new ShiftData.ShiftCallback() { - @Override - public void shift(long start, long end, long offset) { - if (offset > 0) { - for (int i = (int) end; i >= start; i--) { - resultKeys[((int) (i + offset))] = resultKeys[i]; - } - } else { - for (int i = (int) start; i <= end; i++) { - resultKeys[((int) (i + offset))] = resultKeys[i]; - } - } - } - }); - RowSet addedPos = shiftData.getAddedPos(); - - for (RowSet.Iterator iterator = addedPos.iterator(), valueIt = added.iterator(); iterator.hasNext();) { - resultKeys[((int) iterator.nextLong())] = valueIt.nextLong(); - } - - pos = 0; - for (RowSet.Iterator iterator = finalRowSet.iterator(); iterator.hasNext();) { - assertEquals(iterator.nextLong(), resultKeys[pos++]); - } - } - } - - private RowSet getFinalIndex(RowSet initialRowSet, RowSet added, RowSet removed) { - TreeSet finalKeys = new TreeSet(); - for (RowSet.Iterator iterator = initialRowSet.iterator(); iterator.hasNext();) { - Long next = iterator.nextLong(); - finalKeys.add(next); - } - for (RowSet.Iterator iterator = removed.iterator(); iterator.hasNext();) { - Long next = iterator.nextLong(); - finalKeys.remove(next); - } - for (RowSet.Iterator iterator = added.iterator(); iterator.hasNext();) { - Long next = iterator.nextLong(); - finalKeys.add(next); - } - RowSetBuilderRandom builder = RowSetFactory.builderRandom(); - for (Long finalKey : finalKeys) { - builder.addKey(finalKey); - } - return builder.build(); - } - - private RowSet getRandomRemoves(RowSet rowSet, int prob) { - RowSetBuilderRandom builder = RowSetFactory.builderRandom(); - for (RowSet.Iterator iterator = rowSet.iterator(); iterator.hasNext();) { - long next = iterator.nextLong(); - if (random.nextInt(prob) == 0) { - builder.addKey(next); - } - } - return builder.build(); - } - - - private RowSet getBaseIndex(int base, int size) { - RowSetBuilderSequential builder = RowSetFactory.builderSequential(); - for (int i = 0; i < size; i++) { - builder.appendKey(i * size); - } - return builder.build(); - } - - private RowSet getRandomIndex(int base, int offset, int size) { - RowSetBuilderRandom builder = RowSetFactory.builderRandom(); - for (int i = 0; i < size; i++) { - if (random.nextInt(2) == 0) { - builder.addKey(i * base + offset); - } - } - return builder.build(); - } - - - protected RowSet getSortedIndex(long... keys) { - RowSetBuilderRandom builder = RowSetFactory.builderRandom(); - for (long key : keys) { - builder.addKey(key); - } - return builder.build(); - } - -}