java.lang.Object
uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
uk.ac.manchester.tornado.api.types.arrays.LongArray
LongArray relies on preview features of the Java platform:
LongArrayrefers to one or more preview APIs:MemorySegment.
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.-
Field Summary
Fields inherited from class uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
ARRAY_HEADER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all the values of theLongArrayinstance to zero.static LongArraystatic LongArrayfromArray(long[] values) Creates a new instance of theLongArrayclass from an on-heap long array.static LongArrayfromElements(long... values) Creates a new instance of theLongArrayclass from a set of long values.static LongArrayfromLongBuffer(LongBuffer buffer) Creates a new instance of theLongArrayclass from aLongBuffer.static LongArrayfromSegment(MemorySegmentPREVIEW segment) static LongArrayfromSegmentShallow(MemorySegmentPREVIEW segment) Creates a new instance of theLongArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.longget(int index) Gets the long value stored at the specified index of theLongArrayinstance.intlongReturns the number of bytes of theMemorySegmentPREVIEW that is associated with theLongArrayinstance, excluding the header bytes.longReturns the total number of bytes that theMemorySegmentPREVIEW, associated with theLongArrayinstance, occupies.intgetSize()Returns the number of long elements stored in theLongArrayinstance.voidinit(long value) Initializes all the elements of theLongArrayinstance with a specified value.static voidinitialize(LongArray array, long value) Factory method to initialize aLongArray.voidset(int index, long value) Sets the long value at a specified index of theLongArrayinstance.slice(int offset, int length) long[]Converts the long data from off-heap to on-heap, by copying the values of aLongArrayinstance into a new on-heap array.
-
Constructor Details
-
LongArray
public LongArray(int numberOfElements) Constructs a new instance of theLongArraythat will store a user-specified number of elements.- Parameters:
numberOfElements- The number of elements in the array.
-
LongArray
Constructs a newLongArrayinstance by concatenating the contents of the given array ofLongArrayinstances.- Parameters:
arrays- An array ofLongArrayinstances to be concatenated into the new instance.
-
-
Method Details
-
fromArray
Creates a new instance of theLongArrayclass from an on-heap long array.- Parameters:
values- The on-heap long array to create the instance from.- Returns:
- A new
LongArrayinstance, initialized with values of the on-heap long array.
-
fromElements
Creates a new instance of theLongArrayclass from a set of long values.- Parameters:
values- The long values to initialize the array with.- Returns:
- A new
LongArrayinstance, initialized with the given values.
-
fromSegment
- Parameters:
segment- TheMemorySegmentPREVIEW containing the off-heap long data.- Returns:
- A new
LongArrayinstance, initialized with the segment data.
-
fromSegmentShallow
Creates a new instance of theLongArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.- Parameters:
segment- TheMemorySegmentPREVIEW containing *both* the off-heap long *header* and *data*.- Returns:
- A new
LongArrayinstance that wraps the given segment.
-
fromLongBuffer
Creates a new instance of theLongArrayclass from aLongBuffer.- Parameters:
buffer- TheLongBuffercontaining the long data.- Returns:
- A new
LongArrayinstance, initialized with the buffer data.
-
toHeapArray
public long[] toHeapArray()Converts the long data from off-heap to on-heap, by copying the values of aLongArrayinstance into a new on-heap array.- Returns:
- A new on-heap long array, initialized with the values stored in the
LongArrayinstance.
-
set
public void set(int index, long value) Sets the long value at a specified index of theLongArrayinstance.- 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 theLongArrayinstance.- Parameters:
index- The index of which to retrieve the long value.- Returns:
-
clear
public void clear()Sets all the values of theLongArrayinstance to zero.- Specified by:
clearin classTornadoNativeArray
-
getElementSize
public int getElementSize()- Specified by:
getElementSizein classTornadoNativeArray
-
init
public void init(long value) Initializes all the elements of theLongArrayinstance with a specified value.- Parameters:
value- The long value to initialize theLongArrayinstance with.
-
getSize
public int getSize()Returns the number of long elements stored in theLongArrayinstance.- Specified by:
getSizein classTornadoNativeArray- Returns:
-
getSegment
- Specified by:
getSegmentin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theLongArrayinstance.
-
getSegmentWithHeader
- Specified by:
getSegmentWithHeaderin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theLongArrayinstance.
-
getNumBytesOfSegmentWithHeader
public long getNumBytesOfSegmentWithHeader()Returns the total number of bytes that theMemorySegmentPREVIEW, associated with theLongArrayinstance, occupies.- Specified by:
getNumBytesOfSegmentWithHeaderin classTornadoNativeArray- Returns:
- The total number of bytes of the
MemorySegmentPREVIEW.
-
getNumBytesOfSegment
public long getNumBytesOfSegment()Returns the number of bytes of theMemorySegmentPREVIEW that is associated with theLongArrayinstance, excluding the header bytes.- Specified by:
getNumBytesOfSegmentin classTornadoNativeArray- Returns:
- The number of bytes of the raw data in the
MemorySegmentPREVIEW.
-
initialize
Factory method to initialize aLongArray. This method can be invoked from a Task-Graph.- Parameters:
array- Input Array.value- The float value to initialize theLongArrayinstance with.
-
concat
-
slice
- 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
LongArrayinstance representing the specified slice of the original array. - Throws:
IllegalArgumentException- if the specified slice is out of the bounds of the original array.
-
LongArraywhen preview features are enabled.