Package com.illumon.iris.db.v2.utils
Class ChunkUtils
java.lang.Object
com.illumon.iris.db.v2.utils.ChunkUtils
public class ChunkUtils extends Object
-
Constructor Summary
Constructors Constructor Description ChunkUtils()
-
Method Summary
Modifier and Type Method Description static <TARRAY> boolean
canCopyForward(TARRAY srcArray, int srcOffset, TARRAY destArray, int destOffset, int length)
Determines, when copying data from the source array to the dest array, whether the copying should proceed in the forward or reverse direction in order to be safe.static void
checkArrayArgs(int arrayLength, int offset, int capacity)
static void
checkSliceArgs(int size, int offset, int capacity)
static boolean
contains(ByteChunk<? extends Attributes.Any> chunk, byte value)
static boolean
contains(CharChunk<? extends Attributes.Any> chunk, char value)
static boolean
contains(DoubleChunk<? extends Attributes.Any> chunk, double value)
static boolean
contains(FloatChunk<? extends Attributes.Any> chunk, float value)
static boolean
contains(IntChunk<? extends Attributes.Any> chunk, int value)
static boolean
contains(LongChunk<? extends Attributes.Any> chunk, long value)
static boolean
contains(ObjectChunk<?,? extends Attributes.Any> chunk, Object value)
static boolean
contains(ShortChunk<? extends Attributes.Any> chunk, short value)
static LongChunk<Attributes.OrderedKeyIndices>
convertToOrderedKeyIndices(int srcOffset, LongChunk<Attributes.OrderedKeyRanges> chunk)
static void
convertToOrderedKeyIndices(int srcOffset, LongChunk<Attributes.OrderedKeyRanges> chunk, WritableLongChunk<Attributes.OrderedKeyIndices> dest, int destOffset)
static LongChunk<Attributes.OrderedKeyIndices>
convertToOrderedKeyIndices(LongChunk<Attributes.OrderedKeyRanges> chunk)
static WritableLongChunk<Attributes.OrderedKeyRanges>
convertToOrderedKeyRanges(LongChunk<Attributes.OrderedKeyIndices> chunk)
static void
convertToOrderedKeyRanges(LongChunk<Attributes.OrderedKeyIndices> chunk, WritableLongChunk<Attributes.OrderedKeyRanges> dest)
FillsOrderedKeyRanges
intodest
from the providedchunk
and specified source range.static void
copyData(ChunkSource.WithPrev<? extends Attributes.Values>[] src, OrderedKeys srcAllKeys, WritableSource[] dest, OrderedKeys destAllKeys, boolean usePrev)
static void
copyData(ChunkSource.WithPrev<? extends Attributes.Values> src, OrderedKeys srcAllKeys, WritableSource dest, OrderedKeys destAllKeys, boolean usePrev)
static String
dumpChunk(ByteChunk<? extends Attributes.Any> chunk)
static String
dumpChunk(CharChunk<? extends Attributes.Any> chunk)
static String
dumpChunk(Chunk<? extends Attributes.Any> chunk)
static String
dumpChunk(DoubleChunk<? extends Attributes.Any> chunk)
static String
dumpChunk(FloatChunk<? extends Attributes.Any> chunk)
static String
dumpChunk(IntChunk<? extends Attributes.Any> chunk)
static String
dumpChunk(LongChunk<? extends Attributes.Any> chunk)
static String
dumpChunk(ObjectChunk<?,? extends Attributes.Any> chunk)
static String
dumpChunk(ShortChunk<? extends Attributes.Any> chunk)
static String
extractKeyStringFromChunk(Chunk<? extends Attributes.Values> chunk, int chunkPosition)
Produce a pretty key for error messages from an element within parallel chunks.static String
extractKeyStringFromChunk(ChunkType keyChunkType, Chunk<? extends Attributes.Values> chunk, int chunkPosition)
Produce a pretty key for error messages from an element within parallel chunks.static String
extractKeyStringFromChunks(ChunkType[] keyChunkTypes, Chunk<Attributes.Values>[] chunks, int chunkPosition)
Produce a pretty key for error messages from an element within parallel chunks.static <T extends Attributes.Any>
voidfillInOrder(WritableIntChunk<T> inOrderChunk)
Fill inOrderChunk with consecutive integers from 0..size() - 1.static <T extends Attributes.Any>
voidfillInOrder(WritableLongChunk<T> inOrderChunk)
Fill inOrderChunk with consecutive integers from 0..size() - 1.static <T extends Attributes.Values>
voidfillWithNullValue(WritableChunkSink<T> dest, OrderedKeys allKeys)
static <T extends Attributes.Any>
WritableIntChunk<T>makeInOrderIntChunk(int chunkSize)
Make a chunk of integers in order.
-
Constructor Details
-
ChunkUtils
public ChunkUtils()
-
-
Method Details
-
convertToOrderedKeyRanges
public static WritableLongChunk<Attributes.OrderedKeyRanges> convertToOrderedKeyRanges(LongChunk<Attributes.OrderedKeyIndices> chunk)- Parameters:
chunk
- the chunk to convert- Returns:
- the generated chunk
-
convertToOrderedKeyRanges
public static void convertToOrderedKeyRanges(LongChunk<Attributes.OrderedKeyIndices> chunk, WritableLongChunk<Attributes.OrderedKeyRanges> dest)FillsOrderedKeyRanges
intodest
from the providedchunk
and specified source range.- Parameters:
chunk
- the chunk to convertdest
- the chunk to fill with ranges
-
convertToOrderedKeyIndices
public static LongChunk<Attributes.OrderedKeyIndices> convertToOrderedKeyIndices(LongChunk<Attributes.OrderedKeyRanges> chunk)- Parameters:
chunk
- the chunk to convert- Returns:
- the generated chunk
-
convertToOrderedKeyIndices
public static LongChunk<Attributes.OrderedKeyIndices> convertToOrderedKeyIndices(int srcOffset, LongChunk<Attributes.OrderedKeyRanges> chunk)- Parameters:
srcOffset
- the offset intochunk
to begin including in the generated chunkchunk
- the chunk to convert- Returns:
- the generated chunk
-
convertToOrderedKeyIndices
public static void convertToOrderedKeyIndices(int srcOffset, LongChunk<Attributes.OrderedKeyRanges> chunk, WritableLongChunk<Attributes.OrderedKeyIndices> dest, int destOffset)- Parameters:
srcOffset
- the offset intochunk
to begin including in the generated chunkchunk
- the chunk to convertdest
- the chunk to fill with indices
-
extractKeyStringFromChunks
public static String extractKeyStringFromChunks(ChunkType[] keyChunkTypes, Chunk<Attributes.Values>[] chunks, int chunkPosition)Produce a pretty key for error messages from an element within parallel chunks. -
extractKeyStringFromChunk
public static String extractKeyStringFromChunk(ChunkType keyChunkType, Chunk<? extends Attributes.Values> chunk, int chunkPosition)Produce a pretty key for error messages from an element within parallel chunks. -
extractKeyStringFromChunk
public static String extractKeyStringFromChunk(Chunk<? extends Attributes.Values> chunk, int chunkPosition)Produce a pretty key for error messages from an element within parallel chunks. -
checkSliceArgs
public static void checkSliceArgs(int size, int offset, int capacity) -
checkArrayArgs
public static void checkArrayArgs(int arrayLength, int offset, int capacity) -
canCopyForward
public static <TARRAY> boolean canCopyForward(TARRAY srcArray, int srcOffset, TARRAY destArray, int destOffset, int length)Determines, when copying data from the source array to the dest array, whether the copying should proceed in the forward or reverse direction in order to be safe. The issue is that (like memmove), care needs to be taken when the arrays are the same and the ranges overlap. In some cases (like when the arrays are different), either direction will do; in those cases we will recommend copying in the forward direction for performance reasons. When srcArray and destArray refer to the array, one of these five cases applies:Case 1: Source starts to the left of dest, and does not overlap. Recommend copying in forward direction. SSSSS DDDDD Case 2: Source starts to the left of dest, and partially overlaps. MUST copy in the REVERSE direction. SSSSS DDDDD Case 3: Source is on top of dest. Recommend copying in forward direction (really, you should do nothing). SSSSS DDDDD Case 4: Source starts to the right of dest, and partially overlaps. MUST copy in the FORWARD direction. SSSSS DDDDD Case 5: Source starts to the right of dest, and does not overlap. Recommend copying in the forward direction. SSSSS DDDDD
Note that case 2 is the only case where you need to copy backwards.- Parameters:
srcArray
- The source arraysrcOffset
- The starting offset in the srcArraydestArray
- The destination arraydestOffset
- The starting offset in the destination arraylength
- The number of elements that will be copied- Returns:
- true if the copy should proceed in the forward direction; false if it should proceed in the reverse direction
-
dumpChunk
-
dumpChunk
-
dumpChunk
-
dumpChunk
-
dumpChunk
-
dumpChunk
-
dumpChunk
-
dumpChunk
-
dumpChunk
-
contains
-
contains
-
contains
-
contains
-
contains
-
contains
-
contains
-
contains
-
copyData
public static void copyData(ChunkSource.WithPrev<? extends Attributes.Values> src, OrderedKeys srcAllKeys, WritableSource dest, OrderedKeys destAllKeys, boolean usePrev)- Parameters:
src
- The source of the data.srcAllKeys
- The source keys.dest
- The destination of the data (dest != src).destAllKeys
- The destination keys. It is ok for srcAllKeys == destAllKeys.usePrev
- Should we read previous values from src
-
copyData
public static void copyData(ChunkSource.WithPrev<? extends Attributes.Values>[] src, OrderedKeys srcAllKeys, WritableSource[] dest, OrderedKeys destAllKeys, boolean usePrev)- Parameters:
src
- The sources of the data.srcAllKeys
- The source keys.dest
- The destinations of the data (no dest value may appear in src)destAllKeys
- The destination keys. It is ok for srcAllKeys == destAllKeys.usePrev
- Should we read previous values from src
-
fillWithNullValue
public static <T extends Attributes.Values> void fillWithNullValue(WritableChunkSink<T> dest, OrderedKeys allKeys) -
makeInOrderIntChunk
Make a chunk of integers in order.- Parameters:
chunkSize
- the size of the chunk to make- Returns:
- a chunk of integers from 0 to chunkSize - 1
-
fillInOrder
Fill inOrderChunk with consecutive integers from 0..size() - 1.- Parameters:
inOrderChunk
- the chunk to fill
-
fillInOrder
Fill inOrderChunk with consecutive integers from 0..size() - 1.- Parameters:
inOrderChunk
- the chunk to fill
-