Class ChunkUtils

java.lang.Object
com.illumon.iris.db.v2.utils.ChunkUtils

public class ChunkUtils extends Object
  • Constructor Details

    • ChunkUtils

      public ChunkUtils()
  • Method Details

    • convertToOrderedKeyRanges

      public static WritableLongChunk<Attributes.OrderedKeyRanges> convertToOrderedKeyRanges(LongChunk<Attributes.OrderedKeyIndices> chunk)
      Generates a LongChunk<OrderedKeyRanges> from LongChunk<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)
      Fills OrderedKeyRanges into dest from the provided chunk and specified source range.
      Parameters:
      chunk - the chunk to convert
      dest - the chunk to fill with ranges
    • convertToOrderedKeyIndices

      public static LongChunk<Attributes.OrderedKeyIndices> convertToOrderedKeyIndices(LongChunk<Attributes.OrderedKeyRanges> chunk)
      Generates a LongChunk<OrderedKeyIndices> from LongChunk<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)
      Generates a LongChunk<OrderedKeyIndices> from LongChunk<OrderedKeyRanges> chunk.
      Parameters:
      srcOffset - the offset into chunk to begin including in the generated chunk
      chunk - 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)
      Generates a LongChunk<OrderedKeyIndices> from LongChunk<OrderedKeyRanges> chunk.
      Parameters:
      srcOffset - the offset into chunk to begin including in the generated chunk
      chunk - the chunk to convert
      dest - 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 array
      srcOffset - The starting offset in the srcArray
      destArray - The destination array
      destOffset - The starting offset in the destination array
      length - 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

      public static String dumpChunk(Chunk<? extends Attributes.Any> chunk)
    • dumpChunk

      public static String dumpChunk(CharChunk<? extends Attributes.Any> chunk)
    • dumpChunk

      public static String dumpChunk(ByteChunk<? extends Attributes.Any> chunk)
    • dumpChunk

      public static String dumpChunk(ShortChunk<? extends Attributes.Any> chunk)
    • dumpChunk

      public static String dumpChunk(IntChunk<? extends Attributes.Any> chunk)
    • dumpChunk

      public static String dumpChunk(LongChunk<? extends Attributes.Any> chunk)
    • dumpChunk

      public static String dumpChunk(FloatChunk<? extends Attributes.Any> chunk)
    • dumpChunk

      public static String dumpChunk(DoubleChunk<? extends Attributes.Any> chunk)
    • dumpChunk

      public static String dumpChunk(ObjectChunk<?,? extends Attributes.Any> chunk)
    • contains

      public static boolean contains(CharChunk<? extends Attributes.Any> chunk, char value)
    • contains

      public static boolean contains(ByteChunk<? extends Attributes.Any> chunk, byte value)
    • contains

      public static boolean contains(ShortChunk<? extends Attributes.Any> chunk, short value)
    • contains

      public static boolean contains(IntChunk<? extends Attributes.Any> chunk, int value)
    • contains

      public static boolean contains(LongChunk<? extends Attributes.Any> chunk, long value)
    • contains

      public static boolean contains(FloatChunk<? extends Attributes.Any> chunk, float value)
    • contains

      public static boolean contains(DoubleChunk<? extends Attributes.Any> chunk, double value)
    • contains

      public static boolean contains(ObjectChunk<?,? extends Attributes.Any> chunk, Object value)
    • 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

      public static <T extends Attributes.Any> WritableIntChunk<T> makeInOrderIntChunk(int chunkSize)
      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

      public static <T extends Attributes.Any> void fillInOrder(WritableIntChunk<T> inOrderChunk)
      Fill inOrderChunk with consecutive integers from 0..size() - 1.
      Parameters:
      inOrderChunk - the chunk to fill
    • fillInOrder

      public static <T extends Attributes.Any> void fillInOrder(WritableLongChunk<T> inOrderChunk)
      Fill inOrderChunk with consecutive integers from 0..size() - 1.
      Parameters:
      inOrderChunk - the chunk to fill