io.deephaven.chunk.IntChunkChunk 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 CharChunkChunk and run "./gradlew replicateSourcesAndChunks" to regenerate
//
// @formatter:off
package io.deephaven.chunk;
import io.deephaven.chunk.attributes.Any;
public class IntChunkChunk extends ChunkChunkBase implements ChunkChunk {
@SuppressWarnings({"unchecked", "rawtypes"})
private static final IntChunkChunk EMPTY = new IntChunkChunk<>(new IntChunk[0], 0, 0);
public static IntChunkChunk getEmptyChunk() {
// noinspection unchecked
return EMPTY;
}
public static IntChunk[] makeArray(int capacity) {
// noinspection unchecked
return new IntChunk[capacity];
}
public static IntChunkChunk chunkWrap(IntChunk[] data) {
return new IntChunkChunk<>(data, 0, data.length);
}
public static IntChunkChunk chunkWrap(IntChunk[] data, int offset, int capacity) {
return new IntChunkChunk<>(data, offset, capacity);
}
IntChunk[] data;
/**
* innerData[i] is a cached copy of data[i].data used for faster two-dimensional access.
*/
int[][] innerData;
/**
* innerOffsets[i] is a cached copy of data[i].offset used for faster two-dimensional access.
*/
int[] innerOffsets;
IntChunkChunk(IntChunk[] data, int offset, int capacity) {
super(data.length, offset, capacity);
this.data = data;
resetInnerCache(data, offset, 0, capacity);
}
/**
* Update cached "inner" data structures.
*/
final void resetInnerCache(IntChunk[] data, int offset, int oldCapacity, int newCapacity) {
if (innerData == null || innerData.length < newCapacity) {
innerData = new int[newCapacity][];
innerOffsets = new int[newCapacity];
}
for (int ii = 0; ii < newCapacity; ++ii) {
resetInnerCacheItem(ii, data[ii + offset]);
}
for (int ii = newCapacity; ii < oldCapacity; ++ii) {
// Be friendly to the garbage collector
innerData[ii] = null;
innerOffsets[ii] = 0; // to be nice
}
}
/**
* Update a specific cached "inner" data structures.
*/
final void resetInnerCacheItem(int index, IntChunk chunk) {
if (chunk == null) {
innerData[index] = null;
innerOffsets[index] = 0;
} else {
innerData[index] = chunk.data;
innerOffsets[index] = chunk.offset;
}
}
public final IntChunk get(int index) {
return data[offset + index];
}
public final IntChunk getChunk(int index) {
return get(index);
}
public final int get(int j, int i) {
return innerData[j][innerOffsets[j] + i];
}
@Override
public IntChunkChunk slice(int offset, int capacity) {
ChunkHelpers.checkSliceArgs(size, offset, capacity);
return new IntChunkChunk<>(data, this.offset + offset, capacity);
}
// region AsType
// endregion AsType
}