io.deephaven.chunk.ShortChunkChunk 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 ShortChunkChunk extends ChunkChunkBase implements ChunkChunk {
@SuppressWarnings({"unchecked", "rawtypes"})
private static final ShortChunkChunk EMPTY = new ShortChunkChunk<>(new ShortChunk[0], 0, 0);
public static ShortChunkChunk getEmptyChunk() {
// noinspection unchecked
return EMPTY;
}
public static ShortChunk[] makeArray(int capacity) {
// noinspection unchecked
return new ShortChunk[capacity];
}
public static ShortChunkChunk chunkWrap(ShortChunk[] data) {
return new ShortChunkChunk<>(data, 0, data.length);
}
public static ShortChunkChunk chunkWrap(ShortChunk[] data, int offset, int capacity) {
return new ShortChunkChunk<>(data, offset, capacity);
}
ShortChunk[] data;
/**
* innerData[i] is a cached copy of data[i].data used for faster two-dimensional access.
*/
short[][] innerData;
/**
* innerOffsets[i] is a cached copy of data[i].offset used for faster two-dimensional access.
*/
int[] innerOffsets;
ShortChunkChunk(ShortChunk[] 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(ShortChunk[] data, int offset, int oldCapacity, int newCapacity) {
if (innerData == null || innerData.length < newCapacity) {
innerData = new short[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, ShortChunk chunk) {
if (chunk == null) {
innerData[index] = null;
innerOffsets[index] = 0;
} else {
innerData[index] = chunk.data;
innerOffsets[index] = chunk.offset;
}
}
public final ShortChunk get(int index) {
return data[offset + index];
}
public final ShortChunk getChunk(int index) {
return get(index);
}
public final short get(int j, int i) {
return innerData[j][innerOffsets[j] + i];
}
@Override
public ShortChunkChunk slice(int offset, int capacity) {
ChunkHelpers.checkSliceArgs(size, offset, capacity);
return new ShortChunkChunk<>(data, this.offset + offset, capacity);
}
// region AsType
// endregion AsType
}