io.deephaven.engine.table.impl.join.dupcompact.DoubleReverseDupCompactKernel 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
*/
/*
* ---------------------------------------------------------------------------------------------------------------------
* AUTO-GENERATED CLASS - DO NOT EDIT MANUALLY - for any changes edit CharDupCompactKernel and regenerate
* ---------------------------------------------------------------------------------------------------------------------
*/
package io.deephaven.engine.table.impl.join.dupcompact;
import io.deephaven.util.compare.DoubleComparisons;
import io.deephaven.chunk.*;
import io.deephaven.chunk.attributes.Any;
import io.deephaven.chunk.attributes.ChunkPositions;
import io.deephaven.engine.rowset.chunkattributes.RowKeys;
import org.jetbrains.annotations.NotNull;
public class DoubleReverseDupCompactKernel implements DupCompactKernel {
static final DoubleReverseDupCompactKernel INSTANCE = new DoubleReverseDupCompactKernel();
private DoubleReverseDupCompactKernel() {
// Use the singleton INSTANCE
}
@Override
public int compactDuplicates(
@NotNull final WritableChunk extends Any> chunkToCompact,
@NotNull final WritableLongChunk rowKeys) {
return compactDuplicates(chunkToCompact.asWritableDoubleChunk(), rowKeys);
}
@Override
public int compactDuplicatesPreferFirst(
@NotNull final WritableChunk extends Any> chunkToCompact,
@NotNull final WritableIntChunk chunkPositions) {
return compactDuplicatesPreferFirst(chunkToCompact.asWritableDoubleChunk(), chunkPositions);
}
private static int compactDuplicates(
@NotNull final WritableDoubleChunk extends Any> chunkToCompact,
@NotNull final WritableLongChunk rowKeys) {
final int inputSize = chunkToCompact.size();
if (inputSize == 0) {
return -1;
}
int wpos = 0;
int rpos = 0;
double last = chunkToCompact.get(0);
while (rpos < inputSize) {
final double current = chunkToCompact.get(rpos);
if (!leq(last, current)) {
return rpos;
}
last = current;
while (rpos < inputSize - 1 && eq(current, chunkToCompact.get(rpos + 1))) {
rpos++;
}
chunkToCompact.set(wpos, current);
rowKeys.set(wpos, rowKeys.get(rpos));
rpos++;
wpos++;
}
chunkToCompact.setSize(wpos);
rowKeys.setSize(wpos);
return -1;
}
private static int compactDuplicatesPreferFirst(
@NotNull final WritableDoubleChunk extends Any> chunkToCompact,
@NotNull final WritableIntChunk chunkPositions) {
final int inputSize = chunkToCompact.size();
if (inputSize == 0) {
return -1;
}
int wpos = 0;
int rpos = 0;
double last = chunkToCompact.get(0);
while (rpos < inputSize) {
final double current = chunkToCompact.get(rpos);
if (!leq(last, current)) {
return rpos;
}
last = current;
chunkToCompact.set(wpos, current);
chunkPositions.set(wpos, chunkPositions.get(rpos));
rpos++;
wpos++;
while (rpos < inputSize && eq(current, chunkToCompact.get(rpos))) {
rpos++;
}
}
chunkToCompact.setSize(wpos);
chunkPositions.setSize(wpos);
return -1;
}
// region comparison functions
private static int doComparison(double lhs, double rhs) {
return -1 * DoubleComparisons.compare(lhs, rhs);
}
// endregion comparison functions
private static boolean leq(double lhs, double rhs) {
return doComparison(lhs, rhs) <= 0;
}
private static boolean eq(double lhs, double rhs) {
// region equality function
return DoubleComparisons.eq(lhs, rhs);
// endregion equality function
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy