io.deephaven.chunk.util.hashing.LongChunkHasher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-chunk Show documentation
Show all versions of deephaven-engine-chunk Show documentation
Engine Chunks: Array-like data structures for dense, efficient data movement
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.LongChunk;
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.LongComparisons;
import io.deephaven.util.type.TypeUtils;
import static io.deephaven.chunk.util.hashing.ChunkHasher.scrambleHash;
public class LongChunkHasher implements ChunkHasher {
public static LongChunkHasher INSTANCE = new LongChunkHasher();
private static void hashInitial(LongChunk values, WritableIntChunk destination) {
for (int ii = 0; ii < values.size(); ++ii) {
final long value = values.get(ii);
destination.set(ii, hashInitialSingle(value));
}
destination.setSize(values.size());
}
private static void hashSecondary(LongChunk 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(long value) {
return scrambleHash(LongComparisons.hashCode(value));
}
public static int hashUpdateSingle(int existing, long newValue) {
return existing * 31 + hashInitialSingle(newValue);
}
@Override
public int hashInitial(Object value) {
return hashInitialSingle(TypeUtils.unbox((Long) value));
}
@Override
public int hashUpdate(int existing, Object value) {
return hashUpdateSingle(existing, TypeUtils.unbox((Long) value));
}
@Override
public void hashInitial(Chunk values, WritableIntChunk destination) {
hashInitial(values.asLongChunk(), destination);
}
@Override
public void hashUpdate(Chunk values, WritableIntChunk destination) {
hashSecondary(values.asLongChunk(), destination);
}
}