Module tornado.api

Class LongArray

java.lang.Object
uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
uk.ac.manchester.tornado.api.types.arrays.LongArray

public final class LongArray extends TornadoNativeArray
LongArray relies on preview features of the Java platform:
Programs can only use LongArray when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
This class represents an array of longs stored in native memory. The long data is stored in a MemorySegmentPREVIEW, which represents a contiguous region of off-heap memory. The class also encapsulates methods for setting and getting long values, for initializing the long array, and for converting the array to and from different representations.
  • Constructor Details

    • LongArray

      public LongArray(int numberOfElements)
      Constructs a new instance of the LongArray that will store a user-specified number of elements.
      Parameters:
      numberOfElements - The number of elements in the array.
    • LongArray

      public LongArray(LongArray... arrays)
      Constructs a new LongArray instance by concatenating the contents of the given array of LongArray instances.
      Parameters:
      arrays - An array of LongArray instances to be concatenated into the new instance.
  • Method Details

    • fromArray

      public static LongArray fromArray(long[] values)
      Creates a new instance of the LongArray class from an on-heap long array.
      Parameters:
      values - The on-heap long array to create the instance from.
      Returns:
      A new LongArray instance, initialized with values of the on-heap long array.
    • fromElements

      public static LongArray fromElements(long... values)
      Creates a new instance of the LongArray class from a set of long values.
      Parameters:
      values - The long values to initialize the array with.
      Returns:
      A new LongArray instance, initialized with the given values.
    • fromSegment

      public static LongArray fromSegment(MemorySegmentPREVIEW segment)
      Creates a new instance of the LongArray class from a MemorySegmentPREVIEW.
      Parameters:
      segment - The MemorySegmentPREVIEW containing the off-heap long data.
      Returns:
      A new LongArray instance, initialized with the segment data.
    • fromSegmentShallow

      public static LongArray fromSegmentShallow(MemorySegmentPREVIEW segment)
      Creates a new instance of the LongArray class by wrapping an existing MemorySegmentPREVIEW without copying its contents.
      Parameters:
      segment - The MemorySegmentPREVIEW containing *both* the off-heap long *header* and *data*.
      Returns:
      A new LongArray instance that wraps the given segment.
    • fromLongBuffer

      public static LongArray fromLongBuffer(LongBuffer buffer)
      Creates a new instance of the LongArray class from a LongBuffer.
      Parameters:
      buffer - The LongBuffer containing the long data.
      Returns:
      A new LongArray instance, initialized with the buffer data.
    • toHeapArray

      public long[] toHeapArray()
      Converts the long data from off-heap to on-heap, by copying the values of a LongArray instance into a new on-heap array.
      Returns:
      A new on-heap long array, initialized with the values stored in the LongArray instance.
    • set

      public void set(int index, long value)
      Sets the long value at a specified index of the LongArray instance.
      Parameters:
      index - The index at which to set the long value.
      value - The long value to store at the specified index.
    • get

      public long get(int index)
      Gets the long value stored at the specified index of the LongArray instance.
      Parameters:
      index - The index of which to retrieve the long value.
      Returns:
    • clear

      public void clear()
      Sets all the values of the LongArray instance to zero.
      Specified by:
      clear in class TornadoNativeArray
    • getElementSize

      public int getElementSize()
      Specified by:
      getElementSize in class TornadoNativeArray
    • init

      public void init(long value)
      Initializes all the elements of the LongArray instance with a specified value.
      Parameters:
      value - The long value to initialize the LongArray instance with.
    • getSize

      public int getSize()
      Returns the number of long elements stored in the LongArray instance.
      Specified by:
      getSize in class TornadoNativeArray
      Returns:
    • getSegment

      public MemorySegmentPREVIEW getSegment()
      Returns the underlying MemorySegmentPREVIEW of the LongArray instance.
      Specified by:
      getSegment in class TornadoNativeArray
      Returns:
      The MemorySegmentPREVIEW associated with the LongArray instance.
    • getSegmentWithHeader

      public MemorySegmentPREVIEW getSegmentWithHeader()
      Returns the underlying MemorySegmentPREVIEW of the LongArray instance, including the header.
      Specified by:
      getSegmentWithHeader in class TornadoNativeArray
      Returns:
      The MemorySegmentPREVIEW associated with the LongArray instance.
    • getNumBytesOfSegmentWithHeader

      public long getNumBytesOfSegmentWithHeader()
      Returns the total number of bytes that the MemorySegmentPREVIEW, associated with the LongArray instance, occupies.
      Specified by:
      getNumBytesOfSegmentWithHeader in class TornadoNativeArray
      Returns:
      The total number of bytes of the MemorySegmentPREVIEW.
    • getNumBytesOfSegment

      public long getNumBytesOfSegment()
      Returns the number of bytes of the MemorySegmentPREVIEW that is associated with the LongArray instance, excluding the header bytes.
      Specified by:
      getNumBytesOfSegment in class TornadoNativeArray
      Returns:
      The number of bytes of the raw data in the MemorySegmentPREVIEW.
    • initialize

      public static void initialize(LongArray array, long value)
      Factory method to initialize a LongArray. This method can be invoked from a Task-Graph.
      Parameters:
      array - Input Array.
      value - The float value to initialize the LongArray instance with.
    • concat

      public static LongArray concat(LongArray... arrays)
      Concatenates multiple LongArray instances into a single LongArray.
      Parameters:
      arrays - Variable number of LongArray objects to be concatenated.
      Returns:
      A new LongArray instance containing all the elements of the input arrays, concatenated in the order they were provided.
    • slice

      public LongArray slice(int offset, int length)
      Extracts a slice of elements from a given LongArray, creating a new LongArray instance.
      Parameters:
      offset - The starting index from which to begin the slice, inclusive.
      length - The number of elements to include in the slice.
      Returns:
      A new LongArray instance representing the specified slice of the original array.
      Throws:
      IllegalArgumentException - if the specified slice is out of the bounds of the original array.