java.lang.Object
uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
uk.ac.manchester.tornado.api.types.arrays.Int8Array
Int8Array relies on preview features of the Java platform:
Int8Arrayrefers 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.
-
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 theInt8Arrayinstance to zero.static Int8Arraystatic Int8ArrayfromArray(byte[] values) Creates a new instance of theInt8Arrayclass from an on-heap byte.static Int8ArrayfromElements(byte... values) Creates a new instance of theInt8Arrayclass from a set of byte values.static Int8ArrayfromSegment(MemorySegmentPREVIEW segment) static Int8ArrayfromSegmentShallow(MemorySegmentPREVIEW segment) Creates a new instance of theInt8Arrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.byteget(int index) Gets the byte value stored at the specified index of theInt8Arrayinstance.intlongReturns the number of bytes of theMemorySegmentPREVIEW that is associated with theInt8Arrayinstance, excluding the header bytes.longReturns the total number of bytes that theMemorySegmentPREVIEW, associated with theInt8Arrayinstance, occupies.intgetSize()Returns the number of byte (int 8) elements stored in theInt8Arrayinstance.voidinit(byte value) Initializes all the elements of theInt8Arrayinstance with a specified value.static voidinitialize(Int8Array array, byte value) Factory method to initialize aInt8Array.voidset(int index, byte value) Sets the byte value at a specified index of theInt8Arrayinstance.slice(int offset, int length) byte[]Converts the byte array data from off-heap to on-heap, by copying the values of aInt8Arrayinstance into a new on-heap byte array.
-
Constructor Details
-
Int8Array
public Int8Array(int numberOfElements) Constructs a new instance of theInt8Arraythat will store a user-specified number of elements.- Parameters:
numberOfElements- The number of elements in the array.
-
Int8Array
Constructs a newInt8Arrayinstance by concatenating the contents of the given array ofInt8Arrayinstances.- Parameters:
arrays- An array ofInt8Arrayinstances to be concatenated into the new instance.
-
-
Method Details
-
fromArray
Creates a new instance of theInt8Arrayclass from an on-heap byte.- Parameters:
values- The on-heap byte array to create the instance from.- Returns:
- A new
Int8Arrayinstance, initialized with values of the on-heap byte array.
-
fromElements
Creates a new instance of theInt8Arrayclass from a set of byte values.- Parameters:
values- The byte values to initialize the array with.- Returns:
- A new
Int8Arrayinstance, initialized with the given values.
-
fromSegment
- Parameters:
segment- TheMemorySegmentPREVIEW containing the off-heap byte int8 data.- Returns:
- A new
Int8Arrayinstance, initialized with the segment data.
-
fromSegmentShallow
Creates a new instance of theInt8Arrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.- Parameters:
segment- TheMemorySegmentPREVIEW containing *both* the off-heap int8 *header* and *data*.- Returns:
- A new
Int8Arrayinstance that wraps the given segment.
-
toHeapArray
public byte[] toHeapArray()Converts the byte array data from off-heap to on-heap, by copying the values of aInt8Arrayinstance into a new on-heap byte array.- Returns:
- A new on-heap byte array, initialized with the values stored in the
Int8Arrayinstance.
-
set
public void set(int index, byte value) Sets the byte value at a specified index of theInt8Arrayinstance.- Parameters:
index- The index at which to set the byte value.value- The byte value to store at the specified index.
-
get
public byte get(int index) Gets the byte value stored at the specified index of theInt8Arrayinstance.- Parameters:
index- The index of which to retrieve the byte value.- Returns:
-
clear
public void clear()Sets all the values of theInt8Arrayinstance to zero.- Specified by:
clearin classTornadoNativeArray
-
getElementSize
public int getElementSize()- Specified by:
getElementSizein classTornadoNativeArray
-
init
public void init(byte value) Initializes all the elements of theInt8Arrayinstance with a specified value.- Parameters:
value- The byte value to initialize theInt8Arrayinstance with.
-
getSize
public int getSize()Returns the number of byte (int 8) elements stored in theInt8Arrayinstance.- Specified by:
getSizein classTornadoNativeArray- Returns:
-
getSegment
- Specified by:
getSegmentin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theInt8Arrayinstance.
-
getSegmentWithHeader
- Specified by:
getSegmentWithHeaderin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theInt8Arrayinstance.
-
getNumBytesOfSegmentWithHeader
public long getNumBytesOfSegmentWithHeader()Returns the total number of bytes that theMemorySegmentPREVIEW, associated with theInt8Arrayinstance, 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 theInt8Arrayinstance, 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 aInt8Array. This method can be invoked from a Task-Graph.- Parameters:
array- Input Array.value- The byte int8 value to initialize theInt8Arrayinstance 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
Int8Arrayinstance representing the specified slice of the original array. - Throws:
IllegalArgumentException- if the specified slice is out of the bounds of the original array.
-
Int8Arraywhen preview features are enabled.