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

io.deephaven.chunk.util.hashing.ShortToLongCastWithOffset Maven / Gradle / Ivy

The newest version!
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
// ****** AUTO-GENERATED CLASS - DO NOT EDIT MANUALLY
// ****** Edit CharToLongCastWithOffset and run "./gradlew replicateHashing" to regenerate
//
// @formatter:off
package io.deephaven.chunk.util.hashing;

import io.deephaven.chunk.attributes.Any;
import io.deephaven.chunk.ShortChunk;
import io.deephaven.chunk.Chunk;
import io.deephaven.chunk.LongChunk;
import io.deephaven.chunk.WritableLongChunk;

/**
 * Cast the values in the input chunk to an long and add the specified offset.
 *
 * @param  the chunk's attribute
 */
public class ShortToLongCastWithOffset implements ToLongFunctor {
    private final WritableLongChunk result;
    private final long offset;

    ShortToLongCastWithOffset(int size, long offset) {
        result = WritableLongChunk.makeWritableChunk(size);
        this.offset = offset;
    }

    @Override
    public LongChunk apply(Chunk input) {
        return castWithOffset(input.asShortChunk());
    }

    private LongChunk castWithOffset(ShortChunk input) {
        castInto(input, result, offset);
        return result;
    }

    public static  void castInto(ShortChunk input, WritableLongChunk result, long offset) {
        for (int ii = 0; ii < input.size(); ++ii) {
            result.set(ii, (long) input.get(ii) + offset);
        }
        result.setSize(input.size());
    }

    @Override
    public void close() {
        result.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy