Skip to content

Commit

Permalink
Improvements to Vectors using improved iteration and toArray patterns (
Browse files Browse the repository at this point in the history
…deephaven#3570)

* Delete io.deephaven.base.Function, trim down io.deephaven.base.Procedure, and trim down io.deephaven.util.FunctionalInterfaces. Clean up usages of removed interfaces by using standard java.lang or java.util.function alternatives, or by introducing a new, more local interface where appropriate.

* Delete FunctionalInterfaces and promote its members to top-level interfaces in io.deephaven.util.function, with slightly-improved documentation

* Rename and update the remaining functional interfaces in Prodecure to better match the equivalents in java.util.function, promote them to top-level, and move the whole heap to a new engine-primitive module

* Address out-of-date replication in LongSparseArraySource, and moved a block of code (shouldTrackPrevious) in CharacterSparseArraySource to a more appropriate location so it would not be duplicated by region duplication

* Start replicating primitive Consumers

* Don't let Spotless modify replicated code in TestAggregatingDoubleRingBufferTest, and commit the code as-replicated

* Introduce CloseableIterator, and CloseablePrimitiveIteratorOf{Byte, Char, Float, Short, Int, Long, Double}, and adapter functions {Byte, Char, Short}ToIntFunction and FloatToDoubleFunction, which enable adaptation for {Byte, Char, Float, Short} to the built-int PrimitiveIterator specializations, and consequently to IntStream and DoubleStream as appropriate. Extend this stream support to the new iterator interfaces, and use the new iterator interfaces for the ColumnIterators as appropriate.

* Delete deprecated BooleanVector. Remove BooleanVector use in function libraries, and address a few warnings and missed coverage issues in same.

* Get rid of outdated references to "DbArray" and replace with "Vector"

* Code cleanup exercise in Vector and implementations. Standardized code formatting and naming conventions, etc.

* Column iterators now support first row key + length slicing

* Empty, array, repeated, and concatenated iterator support in closeable/primitive iterators

* Support iteration for all vector types and implementations. Use iteration for all vector methods, rather than serial-get. Eliminate Prev*VectorColumnWrappers.

* Update spotless excludes

* Fixed TypedChunk.downcast implementations to take the non-writable versions. Fixed a bunch of inspections and warnings in chunk code. Addressed unnecessarily-restrictive chunk attributes in sort kernels, and did some code cleanup there. Fixed a few bad downcasts.

* Fix VectorColumnWrappers to use chunk filling directly, not iteration, for toArray

* Fix a warning in the chunk pools

* Add boolean flags to control pooled chunk use for writable (enabled) and resettable (disabled) chunks

* Widen the return types for column iterators. Correct a few oversights for methods that are in TableDefaults but should instead be in QueryTable and TableAdapter

* Eliminate an unnecessary constructor for column iterators, and be more assertive about types

* UnionRedirection to not use ThreadLocal priorXSlot caches below a size threshold, defaulted to 128

* Split existing column iterators into interfaces and chunked implementations. Add serial implementations, and switch between the options in vectors based on a size threshold.

* Address replication mismatch for cross join state managers

* Minor cleanups to type code

* Better unit tests for vectors and iterators. Replication for ObjectVectorTest.

* Fix test table sizing and row set builder issue. Address fallout with unit tests that were oversized, missing epsilons, or just "lucky" to dodge internal logical errors.
  • Loading branch information
rcaudy authored Mar 21, 2023
1 parent 1821cc2 commit 1d24619
Show file tree
Hide file tree
Showing 445 changed files with 20,606 additions and 12,131 deletions.
8 changes: 8 additions & 0 deletions Base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ configurations {
artifacts {
tests jarTests
}

spotless {
java {
targetExclude(
'src/test/java/io/deephaven/base/ringbuffer/AggregatingDoubleRingBufferTest.java'
)
}
}
21 changes: 11 additions & 10 deletions Base/src/main/java/io/deephaven/base/ArrayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.deephaven.base.verify.Require;

import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;

public class ArrayUtil {

Expand Down Expand Up @@ -187,40 +189,39 @@ public static <T> boolean replaceInArray(T e, T[] a) {
return false;
}

public static <T> T[] addUnless(T[] a, Class<T> c, Predicate.Unary<T> pred, Function.Nullary<T> factory) {
public static <T> T[] addUnless(T[] a, Class<T> c, Predicate.Unary<T> pred, Supplier<T> factory) {
if (a != null) {
for (int i = 0; i < a.length; ++i) {
if (pred.call(a[i])) {
return a;
}
}
}
return pushArray(factory.call(), a, c);
return pushArray(factory.get(), a, c);
}

public static <T, A> T[] addUnless(T[] a, Class<T> c, Predicate.Binary<T, A> pred, Function.Unary<T, A> factory,
A arg) {
public static <T, A> T[] addUnless(T[] a, Class<T> c, Predicate.Binary<T, A> pred, Function<A, T> factory, A arg) {
if (a != null) {
for (int i = 0; i < a.length; ++i) {
if (pred.call(a[i], arg)) {
return a;
}
}
}
return pushArray(factory.call(arg), a, c);
return pushArray(factory.apply(arg), a, c);
}

public static <T, A> T[] replaceOrAdd(T[] a, Class<T> c, Predicate.Binary<T, A> pred, Function.Unary<T, A> factory,
public static <T, A> T[] replaceOrAdd(T[] a, Class<T> c, Predicate.Binary<T, A> pred, Function<A, T> factory,
A arg) {
if (a != null) {
for (int i = 0; i < a.length; ++i) {
if (pred.call(a[i], arg)) {
a[i] = factory.call(arg);
a[i] = factory.apply(arg);
return a;
}
}
}
return pushArray(factory.call(arg), a, c);
return pushArray(factory.apply(arg), a, c);
}

public static <T> T[] removeIf(T[] a, Predicate.Unary<T> pred) {
Expand Down Expand Up @@ -1469,9 +1470,9 @@ public static int[] intRangeArray(int min, int max) {
return array;
}

public static <T> void init(T[] array, Function.Nullary<T> producer) {
public static <T> void init(T[] array, Supplier<T> producer) {
for (int i = 0; i < array.length; ++i) {
array[i] = producer.call();
array[i] = producer.get();
}
}
}
159 changes: 0 additions & 159 deletions Base/src/main/java/io/deephaven/base/Function.java

This file was deleted.

88 changes: 0 additions & 88 deletions Base/src/main/java/io/deephaven/base/Procedure.java

This file was deleted.

5 changes: 3 additions & 2 deletions Base/src/main/java/io/deephaven/base/RAPriQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package io.deephaven.base;

import java.util.Arrays;
import java.util.function.Function;

/**
* A "random-access" priority queue.
Expand Down Expand Up @@ -189,9 +190,9 @@ public T get(int index) { // index is the "standard" 0..size-1
return (index < size) ? queue[index + 1] : null;
}

public <T2> int dump(T2[] result, int startIndex, Function.Unary<T2, T> f) {
public <T2> int dump(T2[] result, int startIndex, Function<T, T2> f) {
for (int i = 0; i < size; i++) {
result[startIndex++] = f.call(queue[i + 1]);
result[startIndex++] = f.apply(queue[i + 1]);
}
return startIndex;
}
Expand Down
Loading

0 comments on commit 1d24619

Please sign in to comment.