All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.engine.table.impl.util.compact.CompactKernel Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.table.impl.util.compact;

import io.deephaven.chunk.*;
import io.deephaven.chunk.attributes.Any;
import io.deephaven.chunk.attributes.ChunkLengths;
import io.deephaven.chunk.attributes.ChunkPositions;
import io.deephaven.chunk.attributes.Values;

public interface CompactKernel {
    /**
     * Compacts values into the front of the chunk, retaining only values where the parallel retainValues chunk has a
     * true value.
     *
     * @param values a chunk of values, input and output
     * @param retainValues the values to retain
     */
    void compact(WritableChunk values, BooleanChunk retainValues);

    /**
     * Sort valuesChunk, eliminate duplicates, and write the number of times a value occurred into the parallel slot
     * within counts. null values are removed from the chunk.
     *
     * @param valueChunk a chunk of values, input and output
     * @param counts an output chunk parallel to valueChunk with the number of times a value occurred
     */
    default void compactAndCount(WritableChunk valueChunk,
            WritableIntChunk counts) {
        compactAndCount(valueChunk, counts, false);
    }

    /**
     * Sort valuesChunk, eliminate duplicates, and write the number of times a value occurred into the parallel slot
     * within counts.
     *
     * @param valueChunk a chunk of values, input and output
     * @param counts an output chunk parallel to valueChunk with the number of times a value occurred
     * @param countNull if the compaction should count nulls or not
     */
    void compactAndCount(WritableChunk valueChunk,
            WritableIntChunk counts, boolean countNull);

    /**
     * For each run in valuesChunk, sort it, eliminate duplicates, and write the number of times a value occurred into
     * the parallel slot within counts. null values are removed from the chunk.
     *
     * @param valueChunk a chunk of values, input and output
     * @param counts an output chunk parallel to valueChunk with the number of times a value occurred
     * @param startPositions the start of each run
     * @param lengths the length of each run, input and output
     */
    default void compactAndCount(WritableChunk valueChunk,
            WritableIntChunk counts, IntChunk startPositions,
            WritableIntChunk lengths) {
        compactAndCount(valueChunk, counts, startPositions, lengths, false);
    }

    /**
     * For each run in valuesChunk, sort it, eliminate duplicates, and write the number of times a value occurred into
     * the parallel slot within counts.
     *
     * @param valueChunk a chunk of values, input and output
     * @param counts an output chunk parallel to valueChunk with the number of times a value occurred
     * @param startPositions the start of each run
     * @param lengths the length of each run, input and output
     * @param countNull if the compaction should count nulls or not
     */
    void compactAndCount(WritableChunk valueChunk,
            WritableIntChunk counts, IntChunk startPositions,
            WritableIntChunk lengths, boolean countNull);

    static CompactKernel makeCompact(ChunkType chunkType) {
        switch (chunkType) {
            case Boolean:
                return BooleanCompactKernel.INSTANCE;
            case Char:
                return CharCompactKernel.INSTANCE;
            case Byte:
                return ByteCompactKernel.INSTANCE;
            case Short:
                return ShortCompactKernel.INSTANCE;
            case Int:
                return IntCompactKernel.INSTANCE;
            case Long:
                return LongCompactKernel.INSTANCE;
            case Float:
                return FloatCompactKernel.INSTANCE;
            case Double:
                return DoubleCompactKernel.INSTANCE;
            case Object:
                return ObjectCompactKernel.INSTANCE;
            default:
                throw new UnsupportedOperationException();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy