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

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

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

import io.deephaven.chunk.IntChunk;
import io.deephaven.chunk.Chunk;
import io.deephaven.chunk.WritableIntChunk;
import io.deephaven.chunk.attributes.HashCodes;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.util.compare.IntComparisons;
import io.deephaven.util.type.TypeUtils;

import static io.deephaven.chunk.util.hashing.ChunkHasher.scrambleHash;

public class IntChunkHasher implements ChunkHasher {
    public static IntChunkHasher INSTANCE = new IntChunkHasher();

    private static void hashInitial(IntChunk values, WritableIntChunk destination) {
        for (int ii = 0; ii < values.size(); ++ii) {
            final int value = values.get(ii);
            destination.set(ii, hashInitialSingle(value));
        }
        destination.setSize(values.size());
    }

    private static void hashSecondary(IntChunk values, WritableIntChunk destination) {
        for (int ii = 0; ii < values.size(); ++ii) {
            destination.set(ii, hashUpdateSingle(destination.get(ii), values.get(ii)));
        }
        destination.setSize(values.size());
    }

    public static int hashInitialSingle(int value) {
        return scrambleHash(IntComparisons.hashCode(value));
    }

    public static int hashUpdateSingle(int existing, int newValue) {
        return existing * 31 + hashInitialSingle(newValue);
    }

    @Override
    public int hashInitial(Object value) {
        return hashInitialSingle(TypeUtils.unbox((Integer) value));
    }

    @Override
    public int hashUpdate(int existing, Object value) {
        return hashUpdateSingle(existing, TypeUtils.unbox((Integer) value));
    }

    @Override
    public void hashInitial(Chunk values, WritableIntChunk destination) {
        hashInitial(values.asIntChunk(), destination);
    }

    @Override
    public void hashUpdate(Chunk values, WritableIntChunk destination) {
        hashSecondary(values.asIntChunk(), destination);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy