pl.edu.icm.jlargearrays
Class LargeArray
- java.lang.Object
-
- pl.edu.icm.jlargearrays.LargeArray
-
- All Implemented Interfaces:
- java.io.Serializable
- Direct Known Subclasses:
- ByteLargeArray, ComplexDoubleLargeArray, ComplexFloatLargeArray, DoubleLargeArray, FloatLargeArray, IntLargeArray, LogicLargeArray, LongLargeArray, ObjectLargeArray, ShortLargeArray, StringLargeArray, UnsignedByteLargeArray
public abstract class LargeArray extends java.lang.Object implements java.io.SerializableThe base class for all large arrays. All implementations of this abstract class can store up to 263 elements of primitive data types.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static intDEFAULT_MAX_OBJECT_SIZEDefault value of maximal object size.static intDEFAULT_MAX_STRING_LENGTHDefault value of maximal string length.static intLARGEST_SUBARRAYIf the number of elements in an array is greater than the value of LARGEST_SUBARRAY, then getXXXData() methods return null.
-
Constructor Summary
Constructors Constructor and Description LargeArray(java.lang.Object parent, long nativePointer, LargeArrayType largeArrayType, long length)Creates new instance of this class by wrapping a native pointer.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description LargeArrayclone()abstract booleanequals(java.lang.Object o)Indicates whether some other object is "equal to" this one.java.lang.Objectget_safe(long i)Returns a value at index i.abstract java.lang.Objectget(long i)Returns a value at index i.booleangetBoolean_safe(long i)Returns a boolean value at index i.abstract booleangetBoolean(long i)Returns a boolean value at index i.abstract boolean[]getBooleanData()If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns boolean data.abstract boolean[]getBooleanData(boolean[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object.bytegetByte_safe(long i)Returns a signed byte value at index i.abstract bytegetByte(long i)Returns a signed byte value at index i.abstract byte[]getByteData()If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns byte data.abstract byte[]getByteData(byte[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object.abstract java.lang.ObjectgetData()Returns a reference to the internal data array.doublegetDouble_safe(long i)Returns a double value at index i.abstract doublegetDouble(long i)Returns a double value at index i.abstract double[]getDoubleData()If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns double data.abstract double[]getDoubleData(double[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object.floatgetFloat_safe(long i)Returns a float value at index i.abstract floatgetFloat(long i)Returns a float value at index i.abstract float[]getFloatData()If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns float data.abstract float[]getFloatData(float[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object.abstract java.lang.ObjectgetFromNative(long i)Returns a value at index i.intgetInt_safe(long i)Returns an int value at index i.abstract intgetInt(long i)Returns an int value at index i.abstract int[]getIntData()If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns int data.abstract int[]getIntData(int[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object.longgetLong_safe(long i)Returns a long value at index i.abstract longgetLong(long i)Returns a long value at index i.abstract long[]getLongData()If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns long data.abstract long[]getLongData(long[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object.static intgetMaxSizeOf32bitArray()Returns the maximal size of a 32-bit array.shortgetShort_safe(long i)Returns a short value at index i.abstract shortgetShort(long i)Returns a short value at index i.abstract short[]getShortData()If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns short data.abstract short[]getShortData(short[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object.LargeArrayTypegetType()Returns the type of an array.shortgetUnsignedByte_safe(long i)Returns an unsigned byte value at index i.abstract shortgetUnsignedByte(long i)Returns an unsigned byte value at index i.inthashCode()inthashCode(float quality)Generates an approximate hash code using a quality argument.booleanisConstant()Return true if the array is constant.booleanisLarge()Returns true if the off-heap memory is used to store array elements.booleanisNumeric()Returns true if the type of the array is numeric, false otherwise.longlength()Returns the length of an array.longnativePointer()Returns the internal pointer address (if isLarge)voidset_safe(long i, java.lang.Object value)Sets a value at index i.voidset(long i, java.lang.Object value)Sets a value at index i.voidsetBoolean_safe(long i, boolean value)Sets a boolean value at index i.abstract voidsetBoolean(long i, boolean value)Sets a boolean value at index i.voidsetByte_safe(long i, byte value)Sets a byte value at index i.abstract voidsetByte(long i, byte value)Sets a byte value at index i.voidsetDouble_safe(long i, double value)Sets a double value at index i.abstract voidsetDouble(long i, double value)Sets a double value at index i.voidsetFloat_safe(long i, float value)Sets a float value at index i.abstract voidsetFloat(long i, float value)Sets a float value at index i.voidsetInt_safe(long i, int value)Sets an int value at index i.abstract voidsetInt(long i, int value)Sets an int value at index i.voidsetLong_safe(long i, long value)Sets a long value at index i.abstract voidsetLong(long i, long value)Sets a long value at index i.static voidsetMaxSizeOf32bitArray(int index)Sets the maximal size of a 32-bit array.voidsetShort_safe(long i, short value)Sets a short value at index i.abstract voidsetShort(long i, short value)Sets a short value at index i.abstract voidsetToNative(long i, java.lang.Object value)Sets a value at index i.voidsetUnsignedByte_safe(long i, byte value)Sets an unsigned value at index i.abstract voidsetUnsignedByte(long i, short value)Sets an unsigned byte value at index i.
-
-
-
Field Detail
-
LARGEST_SUBARRAY
public static final int LARGEST_SUBARRAY
If the number of elements in an array is greater than the value of LARGEST_SUBARRAY, then getXXXData() methods return null.- See Also:
- Constant Field Values
-
DEFAULT_MAX_STRING_LENGTH
public static final int DEFAULT_MAX_STRING_LENGTH
Default value of maximal string length.- See Also:
- Constant Field Values
-
DEFAULT_MAX_OBJECT_SIZE
public static final int DEFAULT_MAX_OBJECT_SIZE
Default value of maximal object size.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LargeArray
public LargeArray(java.lang.Object parent, long nativePointer, LargeArrayType largeArrayType, long length)Creates new instance of this class by wrapping a native pointer. Providing an invalid pointer, parent or length will result in unpredictable behavior and likely JVM crash. The assumption is that the pointer is valid as long as the parent is not garbage collected.- Parameters:
parent- class instance responsible for handling the pointer's life cycle, the created instance of LargeArray will prevent the GC from reclaiming the parent.nativePointer- native pointer to wrap.largeArrayType- type of arraylength- array length
-
-
Method Detail
-
nativePointer
public long nativePointer()
Returns the internal pointer address (if isLarge)- Returns:
- native pointer address or 0 if not large array.
-
length
public long length()
Returns the length of an array.- Returns:
- the length of an array
-
getType
public LargeArrayType getType()
Returns the type of an array.- Returns:
- the type of an array
-
get
public abstract java.lang.Object get(long i)
Returns a value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- an index- Returns:
- a value at index i.
-
get_safe
public java.lang.Object get_safe(long i)
Returns a value at index i. Array bounds are checked.- Parameters:
i- an index- Returns:
- a value at index i.
-
getFromNative
public abstract java.lang.Object getFromNative(long i)
Returns a value at index i. Array bounds are not checked. If isLarge() returns false for a given array or the index argument is invalid, then calling this method will cause JVM crash.- Parameters:
i- index- Returns:
- a value at index i. The type of returned value is the same as the type of this array.
-
getBoolean
public abstract boolean getBoolean(long i)
Returns a boolean value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- an index- Returns:
- a boolean value at index i.
-
getBoolean_safe
public boolean getBoolean_safe(long i)
Returns a boolean value at index i. Array bounds are checked.- Parameters:
i- an index- Returns:
- a boolean value at index i.
-
getByte
public abstract byte getByte(long i)
Returns a signed byte value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- an index- Returns:
- a value at index i.
-
getByte_safe
public byte getByte_safe(long i)
Returns a signed byte value at index i. Array bounds are checked.- Parameters:
i- an index- Returns:
- a value at index i.
-
getUnsignedByte
public abstract short getUnsignedByte(long i)
Returns an unsigned byte value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- an index- Returns:
- a value at index i.
-
getUnsignedByte_safe
public short getUnsignedByte_safe(long i)
Returns an unsigned byte value at index i. Array bounds are checked.- Parameters:
i- an index- Returns:
- a value at index i.
-
getShort
public abstract short getShort(long i)
Returns a short value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- an index- Returns:
- a value at index i.
-
getShort_safe
public short getShort_safe(long i)
Returns a short value at index i. Array bounds are checked.- Parameters:
i- an index- Returns:
- a value at index i.
-
getInt
public abstract int getInt(long i)
Returns an int value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- an index- Returns:
- a value at index i.
-
getInt_safe
public int getInt_safe(long i)
Returns an int value at index i. Array bounds are checked.- Parameters:
i- an index- Returns:
- a value at index i.
-
getLong
public abstract long getLong(long i)
Returns a long value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- an index- Returns:
- a value at index i.
-
getLong_safe
public long getLong_safe(long i)
Returns a long value at index i. Array bounds are checked.- Parameters:
i- an index- Returns:
- a value at index i.
-
getFloat
public abstract float getFloat(long i)
Returns a float value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- an index- Returns:
- a value at index i.
-
getFloat_safe
public float getFloat_safe(long i)
Returns a float value at index i. Array bounds are checked.- Parameters:
i- an index- Returns:
- a value at index i.
-
getDouble
public abstract double getDouble(long i)
Returns a double value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- an index- Returns:
- a value at index i.
-
getDouble_safe
public double getDouble_safe(long i)
Returns a double value at index i. Array bounds are checked.- Parameters:
i- an index- Returns:
- a value at index i.
-
getData
public abstract java.lang.Object getData()
Returns a reference to the internal data array. For constant arrays the length of the returned array is always equal to 1. If isLarge() returns true, then this method returns null.- Returns:
- reference to the internal data array or null
-
getBooleanData
public abstract boolean[] getBooleanData()
If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns boolean data. Otherwise, it returns null.- Returns:
- an array containing the elements of this object or null
-
getBooleanData
public abstract boolean[] getBooleanData(boolean[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object. Otherwise, it returns null. If (endPos - startPos) / step is smaller or equal to a.length, it is returned therein. Otherwise, a new array is allocated and returned. Array bounds are checked.- Parameters:
a- the array into which the elements are to be stored, if it is big enough; otherwise, a new array of is allocated for this purpose.startPos- starting position (included)endPos- ending position (excluded)step- step size- Returns:
- an array containing the elements of this object or null
-
getByteData
public abstract byte[] getByteData()
If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns byte data. Otherwise, it returns null.- Returns:
- an array containing the elements of this object or null
-
getByteData
public abstract byte[] getByteData(byte[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object. Otherwise, it returns null. If (endPos - startPos) / step is smaller or equal to a.length, it is returned therein. Otherwise, a new array is allocated and returned. Array bounds are checked.- Parameters:
a- the array into which the elements are to be stored, if it is big enough; otherwise, a new array of is allocated for this purpose.startPos- starting position (included)endPos- ending position (excluded)step- step size- Returns:
- an array containing the elements of this object or null
-
getShortData
public abstract short[] getShortData()
If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns short data. Otherwise, it returns null.- Returns:
- an array containing the elements of this object or null
-
getShortData
public abstract short[] getShortData(short[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object. Otherwise, it returns null. If (endPos - startPos) / step is smaller or equal to a.length, it is returned therein. Otherwise, a new array is allocated and returned. Array bounds are checked.- Parameters:
a- the array into which the elements are to be stored, if it is big enough; otherwise, a new array of is allocated for this purpose.startPos- starting position (included)endPos- ending position (excluded)step- step size- Returns:
- an array containing the elements of this object or null
-
getIntData
public abstract int[] getIntData()
If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns int data. Otherwise, it returns null.- Returns:
- an array containing the elements of this object or null
-
getIntData
public abstract int[] getIntData(int[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object. Otherwise, it returns null. If (endPos - startPos) / step is smaller or equal to a.length, it is returned therein. Otherwise, a new array is allocated and returned. Array bounds are checked.- Parameters:
a- the array into which the elements are to be stored, if it is big enough; otherwise, a new array of is allocated for this purpose.startPos- starting position (included)endPos- ending position (excluded)step- step size- Returns:
- an array containing the elements of this object or null
-
getLongData
public abstract long[] getLongData()
If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns long data. Otherwise, it returns null.- Returns:
- an array containing the elements of this object or null
-
getLongData
public abstract long[] getLongData(long[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object. Otherwise, it returns null. If (endPos - startPos) / step is smaller or equal to a.length, it is returned therein. Otherwise, a new array is allocated and returned. Array bounds are checked.- Parameters:
a- the array into which the elements are to be stored, if it is big enough; otherwise, a new array of is allocated for this purpose.startPos- starting position (included)endPos- ending position (excluded)step- step size- Returns:
- an array containing the elements of this object or null
-
getFloatData
public abstract float[] getFloatData()
If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns float data. Otherwise, it returns null.- Returns:
- an array containing the elements of this object or null
-
getFloatData
public abstract float[] getFloatData(float[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object. Otherwise, it returns null. If (endPos - startPos) / step is smaller or equal to a.length, it is returned therein. Otherwise, a new array is allocated and returned. Array bounds are checked.- Parameters:
a- the array into which the elements are to be stored, if it is big enough; otherwise, a new array of is allocated for this purpose.startPos- starting position (included)endPos- ending position (excluded)step- step size- Returns:
- an array containing the elements of this object or null
-
getDoubleData
public abstract double[] getDoubleData()
If the size of the array is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns double data. Otherwise, it returns null.- Returns:
- an array containing the elements of this object or null
-
getDoubleData
public abstract double[] getDoubleData(double[] a, long startPos, long endPos, long step)If (endPos - startPos) / step is smaller than LargeArray.LARGEST_SUBARRAY, then this method returns selected elements of this object. Otherwise, it returns null. If (endPos - startPos) / step is smaller or equal to a.length, it is returned therein. Otherwise, a new array is allocated and returned. Array bounds are checked.- Parameters:
a- the array into which the elements are to be stored, if it is big enough; otherwise, a new array of is allocated for this purpose.startPos- starting position (included)endPos- ending position (excluded)step- step size- Returns:
- an array containing the elements of this object or null
-
set
public void set(long i, java.lang.Object value)Sets a value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- indexvalue- value to set
-
setToNative
public abstract void setToNative(long i, java.lang.Object value)Sets a value at index i. Array bounds are not checked. If isLarge() returns false for a given array or the index argument is invalid, then calling this method will cause JVM crash.- Parameters:
i- indexvalue- value to set- Throws:
java.lang.ClassCastException- if the type of value argument is different than the type of the array
-
set_safe
public void set_safe(long i, java.lang.Object value)Sets a value at index i. Array bounds are checked.- Parameters:
i- indexvalue- value to set
-
setBoolean
public abstract void setBoolean(long i, boolean value)Sets a boolean value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- indexvalue- value to set
-
setBoolean_safe
public void setBoolean_safe(long i, boolean value)Sets a boolean value at index i. Array bounds are checked.- Parameters:
i- indexvalue- value to set
-
setByte
public abstract void setByte(long i, byte value)Sets a byte value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- indexvalue- value to set
-
setByte_safe
public void setByte_safe(long i, byte value)Sets a byte value at index i. Array bounds are checked.- Parameters:
i- indexvalue- value to set
-
setUnsignedByte
public abstract void setUnsignedByte(long i, short value)Sets an unsigned byte value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- indexvalue- value to set
-
setUnsignedByte_safe
public void setUnsignedByte_safe(long i, byte value)Sets an unsigned value at index i. Array bounds are checked.- Parameters:
i- indexvalue- value to set
-
setShort
public abstract void setShort(long i, short value)Sets a short value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- indexvalue- value to set
-
setShort_safe
public void setShort_safe(long i, short value)Sets a short value at index i. Array bounds are checked.- Parameters:
i- indexvalue- value to set
-
setInt
public abstract void setInt(long i, int value)Sets an int value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- indexvalue- value to set
-
setInt_safe
public void setInt_safe(long i, int value)Sets an int value at index i. Array bounds are checked.- Parameters:
i- indexvalue- value to set
-
setLong
public abstract void setLong(long i, long value)Sets a long value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- indexvalue- value to set
-
setLong_safe
public void setLong_safe(long i, long value)Sets a long value at index i. Array bounds are checked.- Parameters:
i- indexvalue- value to set
-
setFloat
public abstract void setFloat(long i, float value)Sets a float value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- indexvalue- value to set
-
setFloat_safe
public void setFloat_safe(long i, float value)Sets a float value at index i. Array bounds are checked.- Parameters:
i- indexvalue- value to set
-
setDouble
public abstract void setDouble(long i, double value)Sets a double value at index i. Array bounds are not checked. Calling this method with invalid index argument will cause JVM crash.- Parameters:
i- indexvalue- value to set
-
setDouble_safe
public void setDouble_safe(long i, double value)Sets a double value at index i. Array bounds are checked.- Parameters:
i- indexvalue- value to set
-
isLarge
public boolean isLarge()
Returns true if the off-heap memory is used to store array elements.- Returns:
- true if the off-heap memory is used to store array elements, false otherwise.
-
isNumeric
public boolean isNumeric()
Returns true if the type of the array is numeric, false otherwise.- Returns:
- true if the type of the array is numeric, false otherwise.
-
isConstant
public boolean isConstant()
Return true if the array is constant. Constant arrays cannot be modified, i.e. all setters throw an IllegalAccessError exception.- Returns:
- true if the arrays is constant, false otherwise
-
setMaxSizeOf32bitArray
public static void setMaxSizeOf32bitArray(int index)
Sets the maximal size of a 32-bit array. For arrays of the size larger than index, the data is stored in the memory allocated by sun.misc.Unsafe.allocateMemory().- Parameters:
index- the maximal size of a 32-bit array.
-
getMaxSizeOf32bitArray
public static int getMaxSizeOf32bitArray()
Returns the maximal size of a 32-bit array.- Returns:
- the maximal size of a 32-bit array.
-
clone
public LargeArray clone()
- Overrides:
clonein classjava.lang.Object
-
equals
public abstract boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one. Theequalsmethod implements "deep comparison": all properties are compared and all corresponding elements in both arrays are compared.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the reference object with which to compare.- Returns:
trueif this object is the same as the o argument;falseotherwise.- See Also:
hashCode(),HashMap
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
hashCode
public int hashCode(float quality)
Generates an approximate hash code using a quality argument. For quality equal to 1 this method is equivalent to hashCode().- Parameters:
quality- a number between 0 and 1.- Returns:
- an approximate hash code
-
-
DataMelt 3.0 © DataMelt by jWork.ORG