Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.deephaven.engine.table.impl.by.ObjectChunkedAddOnlyMinMaxOperator Maven / Gradle / Ivy
Go to download
Engine Table: Implementation and closely-coupled utilities
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
/*
* ---------------------------------------------------------------------------------------------------------------------
* AUTO-GENERATED CLASS - DO NOT EDIT MANUALLY - for any changes edit CharChunkedAddOnlyMinMaxOperator and regenerate
* ---------------------------------------------------------------------------------------------------------------------
*/
package io.deephaven.engine.table.impl.by;
import io.deephaven.chunk.attributes.ChunkLengths;
import io.deephaven.chunk.attributes.ChunkPositions;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.rowset.chunkattributes.RowKeys;
import io.deephaven.util.compare.ObjectComparisons;
import io.deephaven.engine.table.impl.sources.ObjectArraySource;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.chunk.*;
import org.apache.commons.lang3.mutable.MutableInt;
import java.util.Collections;
import java.util.Map;
/**
* Iterative average operator.
*/
class ObjectChunkedAddOnlyMinMaxOperator implements IterativeChunkedAggregationOperator {
private final ObjectArraySource resultColumn;
// region actualResult
// endregion actualResult
private final boolean minimum;
private final String name;
ObjectChunkedAddOnlyMinMaxOperator(
// region extra constructor params
Class> type,
// endregion extra constructor params
boolean minimum, String name) {
this.minimum = minimum;
this.name = name;
// region resultColumn initialization
resultColumn = new ObjectArraySource<>(type);
// endregion resultColumn initialization
}
private Object min(ObjectChunk values, MutableInt chunkNonNull, int chunkStart, int chunkEnd) {
int nonNull = 0;
Object value = null;
for (int ii = chunkStart; ii < chunkEnd; ++ii) {
final Object candidate = values.get(ii);
if (candidate != null) {
if (nonNull++ == 0) {
value = candidate;
} else if (ObjectComparisons.lt(candidate, value)) {
value = candidate;
}
}
}
chunkNonNull.setValue(nonNull);
return value;
}
private Object max(ObjectChunk values, MutableInt chunkNonNull, int chunkStart, int chunkEnd) {
int nonNull =0;
Object value = null;
for (int ii = chunkStart; ii < chunkEnd; ++ii) {
final Object candidate = values.get(ii);
if (candidate != null) {
if (nonNull++ == 0) {
value = candidate;
} else if (ObjectComparisons.gt(candidate, value)) {
value = candidate;
}
}
}
chunkNonNull.setValue(nonNull);
return value;
}
private Object min(Object a, Object b) {
return ObjectComparisons.lt(a, b) ? a : b;
}
private Object max(Object a, Object b) {
return ObjectComparisons.gt(a, b) ? a : b;
}
@Override
public void addChunk(BucketedContext bucketedContext, Chunk extends Values> values, LongChunk extends RowKeys> inputRowKeys, IntChunk destinations, IntChunk startPositions, IntChunk length, WritableBooleanChunk stateModified) {
final ObjectChunk asObjectChunk = values.asObjectChunk();
for (int ii = 0; ii < startPositions.size(); ++ii) {
final int startPosition = startPositions.get(ii);
final long destination = destinations.get(startPosition);
stateModified.set(ii, addChunk(asObjectChunk, destination, startPosition, length.get(ii)));
}
}
@Override
public void removeChunk(BucketedContext context, Chunk extends Values> values, LongChunk extends RowKeys> inputRowKeys, IntChunk destinations, IntChunk startPositions, IntChunk length, WritableBooleanChunk stateModified) {
throw new UnsupportedOperationException();
}
@Override
public void modifyChunk(BucketedContext context, Chunk extends Values> previousValues, Chunk extends Values> newValues, LongChunk extends RowKeys> postShiftRowKeys, IntChunk destinations, IntChunk startPositions, IntChunk length, WritableBooleanChunk stateModified) {
throw new UnsupportedOperationException();
}
@Override
public boolean addChunk(SingletonContext context, int chunkSize, Chunk extends Values> values, LongChunk extends RowKeys> inputRowKeys, long destination) {
return addChunk(values.asObjectChunk(), destination, 0, values.size());
}
@Override
public boolean removeChunk(SingletonContext context, int chunkSize, Chunk extends Values> values, LongChunk extends RowKeys> inputRowKeys, long destination) {
throw new UnsupportedOperationException();
}
@Override
public boolean modifyChunk(SingletonContext context, int chunkSize, Chunk extends Values> previousValues, Chunk extends Values> newValues, LongChunk extends RowKeys> postShiftRowKeys, long destination) {
throw new UnsupportedOperationException();
}
private boolean addChunk(ObjectChunk values, long destination, int chunkStart, int chunkSize) {
if (chunkSize == 0) {
return false;
}
final MutableInt chunkNonNull = new MutableInt(0);
final int chunkEnd = chunkStart + chunkSize;
final Object chunkValue = minimum ? min(values, chunkNonNull, chunkStart, chunkEnd) : max(values, chunkNonNull, chunkStart, chunkEnd);
if (chunkNonNull.intValue() == 0) {
return false;
}
final Object result;
final Object oldValue = resultColumn.getUnsafe(destination);
if (oldValue == null) {
// we exclude nulls from the min/max calculation, therefore if the value in our min/max is null we know
// that it is in fact empty and we should use the value from the chunk
result = chunkValue;
} else {
result = minimum ? min(chunkValue, oldValue) : max(chunkValue, oldValue);
}
if (!ObjectComparisons.eq(result, oldValue)) {
resultColumn.set(destination, result);
return true;
} else {
return false;
}
}
@Override
public void ensureCapacity(long tableSize) {
resultColumn.ensureCapacity(tableSize);
}
@Override
public Map> getResultColumns() {
// region getResultColumns
return Collections.>singletonMap(name, resultColumn);
// endregion getResultColumns
}
@Override
public void startTrackingPrevValues() {
resultColumn.startTrackingPrevValues();
}
}