io.deephaven.engine.table.impl.by.SumBigDecimalChunk 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
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.table.impl.by;
import io.deephaven.chunk.ObjectChunk;
import io.deephaven.chunk.attributes.Values;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.lang3.mutable.MutableObject;
import java.math.BigDecimal;
class SumBigDecimalChunk {
private SumBigDecimalChunk() {} // static use only
static BigDecimal sumBigDecimalChunk(ObjectChunk values, int chunkStart,
int chunkSize, MutableInt chunkNonNull) {
BigDecimal partialSum = BigDecimal.ZERO;
for (int ii = chunkStart; ii < chunkStart + chunkSize; ++ii) {
final BigDecimal value = values.get(ii);
if (value != null) {
chunkNonNull.increment();
partialSum = partialSum.add(value);
}
}
return partialSum;
}
static BigDecimal sumBigDecimalChunkAbs(ObjectChunk values, int chunkStart,
int chunkSize, MutableInt chunkNonNull) {
BigDecimal partialSum = BigDecimal.ZERO;
for (int ii = chunkStart; ii < chunkStart + chunkSize; ++ii) {
final BigDecimal value = values.get(ii);
if (value != null) {
chunkNonNull.increment();
partialSum = partialSum.add(value.abs());
}
}
return partialSum;
}
static BigDecimal sum2BigDecimalChunk(ObjectChunk values, int chunkStart,
int chunkSize, MutableInt chunkNonNull, MutableObject sum2out) {
final int end = chunkStart + chunkSize;
BigDecimal sum = BigDecimal.ZERO;
BigDecimal sum2 = BigDecimal.ZERO;
for (int ii = chunkStart; ii < end; ++ii) {
final BigDecimal value = values.get(ii);
if (value != null) {
sum = sum.add(value);
sum2 = sum2.add(value.pow(2));
chunkNonNull.increment();
}
}
sum2out.setValue(sum2);
return sum;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy