io.deephaven.engine.table.impl.sources.regioned.ColumnRegionByte Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.table.impl.sources.regioned;
import io.deephaven.chunk.attributes.Any;
import io.deephaven.chunk.ChunkType;
import io.deephaven.chunk.WritableChunk;
import io.deephaven.engine.page.PagingContextHolder;
import io.deephaven.util.QueryConstants;
import io.deephaven.util.annotations.FinalDefault;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
/**
* Column region interface for regions that support fetching primitive bytes.
*/
public interface ColumnRegionByte extends ColumnRegion {
/**
* Get a single byte from this region.
*
* @param elementIndex Element row key in the table's address space
* @return The byte value at the specified element row key
*/
byte getByte(long elementIndex);
/**
* Get a single byte from this region.
*
* @param context A {@link PagingContextHolder} to enable resource caching where suitable, with current
* region index pointing to this region
* @param elementIndex Element row key in the table's address space
* @return The byte value at the specified element row ket
*/
default byte getByte(@NotNull final FillContext context, final long elementIndex) {
return getByte(elementIndex);
}
/**
* Get a range of bytes from this region. Implementations are not required to verify that the range specified is
* meaningful.
*
* @param firstElementIndex First element row keyt in the table's address space
* @param destination Array to store results
* @param destinationOffset Offset into {@code destination} to begin storing at
* @param length Number of bytes to get
* @return {@code destination}, to enable method chaining
*/
byte[] getBytes(long firstElementIndex,
@NotNull byte[] destination,
int destinationOffset,
int length
);
@Override
@FinalDefault
default ChunkType getChunkType() {
return ChunkType.Byte;
}
static ColumnRegionByte createNull(final long pageMask) {
//noinspection unchecked
return pageMask == Null.DEFAULT_INSTANCE.mask() ? Null.DEFAULT_INSTANCE : new Null(pageMask);
}
final class Null extends ColumnRegion.Null implements ColumnRegionByte {
@SuppressWarnings("rawtypes")
private static final ColumnRegionByte DEFAULT_INSTANCE = new ColumnRegionByte.Null(RegionedColumnSourceBase.PARAMETERS.regionMask);
private Null(final long pageMask) {
super(pageMask);
}
@Override
public byte getByte(final long elementIndex) {
return QueryConstants.NULL_BYTE;
}
@Override
public byte[] getBytes(final long firstElementIndex, @NotNull final byte[] destination, final int destinationOffset, final int length) {
Arrays.fill(destination, destinationOffset, destinationOffset + length, QueryConstants.NULL_BYTE);
return destination;
}
}
final class Constant
extends GenericColumnRegionBase
implements ColumnRegionByte, WithDefaultsForRepeatingValues {
private final byte value;
public Constant(final long pageMask, final byte value) {
super(pageMask);
this.value = value;
}
@Override
public byte getByte(final long elementIndex) {
return value;
}
@Override
public void fillChunkAppend(@NotNull final FillContext context, @NotNull final WritableChunk super ATTR> destination, final int length) {
final int offset = destination.size();
destination.asWritableByteChunk().fillWithValue(offset, length, value);
destination.setSize(offset + length);
}
@Override
public byte[] getBytes(final long firstElementIndex, @NotNull final byte[] destination, final int destinationOffset, final int length) {
Arrays.fill(destination, destinationOffset, destinationOffset + length, value);
return destination;
}
}
final class StaticPageStore
extends RegionedPageStore.Static>
implements ColumnRegionByte {
public StaticPageStore(@NotNull final Parameters parameters, @NotNull final ColumnRegionByte[] regions) {
super(parameters, regions);
}
@Override
public void invalidate() {
for(int ii = 0; ii < getRegionCount(); ii++) {
getRegion(ii).invalidate();
}
}
@Override
public byte getByte(final long elementIndex) {
return lookupRegion(elementIndex).getByte(elementIndex);
}
@Override
public byte getByte(@NotNull final FillContext context, final long elementIndex) {
return lookupRegion(elementIndex).getByte(context, elementIndex);
}
@Override
public byte[] getBytes(final long firstElementIndex, @NotNull final byte[] destination, final int destinationOffset, final int length) {
return lookupRegion(firstElementIndex).getBytes(firstElementIndex, destination, destinationOffset, length);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy