io.deephaven.engine.table.impl.updateby.rollingminmax.FloatRollingMinMaxOperator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
/*
* ---------------------------------------------------------------------------------------------------------------------
* AUTO-GENERATED CLASS - DO NOT EDIT MANUALLY - for any changes edit CharRollingMinMaxOperator and regenerate
* ---------------------------------------------------------------------------------------------------------------------
*/
package io.deephaven.engine.table.impl.updateby.rollingminmax;
import io.deephaven.base.ringbuffer.AggregatingFloatRingBuffer;
import io.deephaven.base.verify.Assert;
import io.deephaven.chunk.FloatChunk;
import io.deephaven.chunk.Chunk;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.table.impl.MatchPair;
import io.deephaven.engine.table.impl.updateby.UpdateByOperator;
import io.deephaven.engine.table.impl.updateby.internal.BaseFloatUpdateByOperator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static io.deephaven.util.QueryConstants.NULL_FLOAT;
public class FloatRollingMinMaxOperator extends BaseFloatUpdateByOperator {
private final boolean isMax;
private static final int BUFFER_INITIAL_CAPACITY = 128;
// region extra-fields
// endregion extra-fields
protected class Context extends BaseFloatUpdateByOperator.Context {
protected FloatChunk extends Values> floatInfluencerValuesChunk;
protected AggregatingFloatRingBuffer aggMinMax;
protected boolean evaluationNeeded;
@SuppressWarnings("unused")
protected Context(final int affectedChunkSize, final int influencerChunkSize) {
super(affectedChunkSize);
if (isMax) {
aggMinMax = new AggregatingFloatRingBuffer(BUFFER_INITIAL_CAPACITY, NULL_FLOAT, (a, b) -> {
if (a == NULL_FLOAT) {
return b;
} else if (b == NULL_FLOAT) {
return a;
}
return (float)Math.max(a, b);
});
} else {
aggMinMax = new AggregatingFloatRingBuffer(BUFFER_INITIAL_CAPACITY, Float.MAX_VALUE, (a, b) -> {
if (a == NULL_FLOAT) {
return b;
} else if (b == NULL_FLOAT) {
return a;
}
return (float)Math.min(a, b);
});
}
curVal = isMax ? NULL_FLOAT : Float.MAX_VALUE;
evaluationNeeded = false;
}
@Override
public void close() {
super.close();
aggMinMax = null;
}
@Override
public void setValueChunks(@NotNull final Chunk extends Values>[] valueChunks) {
floatInfluencerValuesChunk = valueChunks[0].asFloatChunk();
}
@Override
public void push(int pos, int count) {
aggMinMax.ensureRemaining(count);
for (int ii = 0; ii < count; ii++) {
float val = floatInfluencerValuesChunk.get(pos + ii);
aggMinMax.addUnsafe(val);
if (val == NULL_FLOAT) {
nullCount++;
} else if (curVal == NULL_FLOAT) {
curVal = val;
evaluationNeeded = false;
} else if (isMax && curVal < val) {
curVal = val;
// Can skip evaluation when we push a new extreme.
evaluationNeeded = false;
} else if (!isMax && curVal > val) {
curVal = val;
// Can skip evaluation when we push a new extreme.
evaluationNeeded = false;
}
}
}
@Override
public void pop(int count) {
Assert.geq(aggMinMax.size(), "floatWindowValues.size()", count);
for (int ii = 0; ii < count; ii++) {
float val = aggMinMax.removeUnsafe();
if (val == NULL_FLOAT) {
nullCount--;
} else {
// Only revaluate if we pop something equal to our current value. Otherwise we have perfect
// confidence that the min/max is still in the window.
if (curVal == val) {
evaluationNeeded = true;
}
}
}
}
@Override
public void writeToOutputChunk(int outIdx) {
if (aggMinMax.size() == nullCount) {
curVal = NULL_FLOAT;
} else if (evaluationNeeded) {
curVal = aggMinMax.evaluate();
}
outputValues.set(outIdx, curVal);
evaluationNeeded = false;
}
@Override
public void reset() {
super.reset();
aggMinMax.clear();
curVal = isMax ? NULL_FLOAT : Float.MAX_VALUE;
evaluationNeeded = false;
}
}
@NotNull
@Override
public UpdateByOperator.Context makeUpdateContext(final int affectedChunkSize, final int influencerChunkSize) {
return new Context(affectedChunkSize, influencerChunkSize);
}
public FloatRollingMinMaxOperator(
@NotNull final MatchPair pair,
@NotNull final String[] affectingColumns,
@Nullable final String timestampColumnName,
final long reverseWindowScaleUnits,
final long forwardWindowScaleUnits,
final boolean isMax
// region extra-constructor-args
// endregion extra-constructor-args
) {
super(pair, affectingColumns, timestampColumnName, reverseWindowScaleUnits, forwardWindowScaleUnits, true);
this.isMax = isMax;
// region constructor
// endregion constructor
}
@Override
public UpdateByOperator copy() {
return new FloatRollingMinMaxOperator(
pair,
affectingColumns,
timestampColumnName,
reverseWindowScaleUnits,
forwardWindowScaleUnits,
isMax
// region extra-copy-args
// endregion extra-copy-args
);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy