|
| 1 | +// |
| 2 | +// Copyright (c) 2016-2025 Deephaven Data Labs and Patent Pending |
| 3 | +// |
| 4 | +package io.deephaven.engine.table.impl.updateby.minmax; |
| 5 | + |
| 6 | +import io.deephaven.base.verify.Assert; |
| 7 | +import io.deephaven.chunk.Chunk; |
| 8 | +import io.deephaven.chunk.CharChunk; |
| 9 | +import io.deephaven.chunk.attributes.Values; |
| 10 | +import io.deephaven.engine.table.impl.MatchPair; |
| 11 | +import io.deephaven.engine.table.impl.updateby.UpdateByOperator; |
| 12 | +import io.deephaven.engine.table.impl.updateby.internal.BaseCharUpdateByOperator; |
| 13 | +import org.jetbrains.annotations.NotNull; |
| 14 | + |
| 15 | +import static io.deephaven.util.QueryConstants.*; |
| 16 | + |
| 17 | +public class CharCumMinMaxOperator extends BaseCharUpdateByOperator { |
| 18 | + private final boolean isMax; |
| 19 | + |
| 20 | + // region extra-fields |
| 21 | + // endregion extra-fields |
| 22 | + |
| 23 | + protected class Context extends BaseCharUpdateByOperator.Context { |
| 24 | + public CharChunk<? extends Values> charValueChunk; |
| 25 | + |
| 26 | + protected Context(final int chunkSize) { |
| 27 | + super(chunkSize); |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + public void setValueChunks(@NotNull final Chunk<? extends Values>[] valueChunks) { |
| 32 | + charValueChunk = valueChunks[0].asCharChunk(); |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public void push(int pos, int count) { |
| 37 | + Assert.eq(count, "push count", 1); |
| 38 | + |
| 39 | + final char val = charValueChunk.get(pos); |
| 40 | + |
| 41 | + if (curVal == NULL_CHAR) { |
| 42 | + curVal = val; |
| 43 | + } else if (val != NULL_CHAR) { |
| 44 | + if ((isMax && val > curVal) || |
| 45 | + (!isMax && val < curVal)) { |
| 46 | + curVal = val; |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + public CharCumMinMaxOperator( |
| 53 | + @NotNull final MatchPair pair, |
| 54 | + final boolean isMax |
| 55 | + // region extra-constructor-args |
| 56 | + // endregion extra-constructor-args |
| 57 | + ) { |
| 58 | + super(pair, new String[] {pair.rightColumn}); |
| 59 | + this.isMax = isMax; |
| 60 | + // region constructor |
| 61 | + // endregion constructor |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public UpdateByOperator copy() { |
| 66 | + return new CharCumMinMaxOperator( |
| 67 | + pair, |
| 68 | + isMax |
| 69 | + // region extra-copy-args |
| 70 | + // endregion extra-copy-args |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + @NotNull |
| 75 | + @Override |
| 76 | + public UpdateByOperator.Context makeUpdateContext(final int affectedChunkSize, final int influencerChunkSize) { |
| 77 | + return new Context(affectedChunkSize); |
| 78 | + } |
| 79 | + |
| 80 | + // region extra-methods |
| 81 | + // endregion extra-methods |
| 82 | +} |
0 commit comments