Skip to content

Commit

Permalink
refactor!: Remove gnu.trove from RowSet API (deephaven#5730)
Browse files Browse the repository at this point in the history
Removes usages of gnu.trove from the API of rowset related classes.
These usages were previously unused, though this is technically an API
breaking change.

Partial deephaven#188
Co-authored-by: Ryan Caudy <[email protected]>
  • Loading branch information
niloc132 authored Jul 12, 2024
1 parent 5483dbc commit e872f06
Show file tree
Hide file tree
Showing 35 changed files with 69 additions and 668 deletions.
2 changes: 1 addition & 1 deletion engine/rowset/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
10 changes: 0 additions & 10 deletions engine/rowset/src/main/java/io/deephaven/engine/rowset/RowSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -61,12 +60,6 @@ default void appendOrderedRowKeyRangesChunk(final LongChunk<OrderedRowKeyRanges>
appendRanges(new LongChunkRangeIterator(chunk));
}

@Override
default boolean execute(final long value) {
appendKey(value);
return true;
}

/**
* Appends a {@link RowSequence} to this builder.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -56,21 +54,6 @@ public static WritableRowSet fromKeys(final long rowKey) {
return fromRange(rowKey, rowKey);
}

/**
* Get a {@link WritableRowSet} containing the specified row keys.
* <p>
* 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].
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -224,26 +225,14 @@ 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}.
* <p>
* Use this to move from pre-shift keyspace to post-shift keyspace.
*
* @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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,7 +46,7 @@
*/
public abstract class ArrayBackedColumnSource<T>
extends AbstractColumnSource<T>
implements FillUnordered<Values>, ShiftData.ShiftCallback, WritableColumnSource<T>, InMemoryColumnSource,
implements FillUnordered<Values>, WritableColumnSource<T>, InMemoryColumnSource,
ChunkedBackingStoreExposedWritableSource {

static final int DEFAULT_RECYCLER_CAPACITY = 1024;
Expand Down Expand Up @@ -426,20 +425,6 @@ public static <T> WritableColumnSource<T> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit e872f06

Please sign in to comment.