|
AlgART Home | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface PArray extends Array
AlgART array of primitive elements (boolean, char, byte, short, int, long, float or double), read-only access.
Any class implementing this interface must implement one of
BitArray, CharArray,
ByteArray, ShortArray,
IntArray, LongArray,
FloatArray, DoubleArray
subinterfaces.
AlgART Laboratory 2007-2013
| Modifier and Type | Method and Description |
|---|---|
PArray |
asImmutable()
Returns an immutable view of this array. |
PArray |
asTrustedImmutable()
Returns a trusted immutable view of this array. |
long |
bitsPerElement()
Return the number of memory bits occupied by every element of this array. |
double |
getDouble(long index)
Returns the element #index converted to double: (double)(value&0xFF) for byte value, (double)(value&0xFFFF) for short value, (double)value for int, long, float, double, char values, or value?1.0:0.0 for boolean values. |
long |
indexOf(long lowIndex,
long highIndex,
double value)
Returns the minimal index k, so that lowIndex<=k<min(highIndex,thisArray. length())
and getDouble(k)==value,
or -1 if there is no such array element. |
boolean |
isZeroFilled()
Returns true if all elements of this array are zero (false for boolean[] array, (char)0 for char[]). |
long |
lastIndexOf(long lowIndex,
long highIndex,
double value)
Returns the maximal index k, so that highIndex>k>=max(lowIndex,0) and getDouble(k)==value,
or -1 if there is no such array element. |
double |
maxPossibleValue(double valueForFloatingPoint)
Returns 1 for BitArray,
0xFF for ByteArray,
0xFFFF for CharArray and ShortArray,
Integer.MAX_VALUE for IntArray,
Long.MAX_VALUE for LongArray,
valueForFloatingPoint for FloatArray and DoubleArray. |
double |
minPossibleValue(double valueForFloatingPoint)
Returns 0 for BitArray, ByteArray, CharArray and ShortArray,
Integer.MIN_VALUE for IntArray,
Long.MIN_VALUE for LongArray,
valueForFloatingPoint for FloatArray and DoubleArray. |
MutablePArray |
mutableClone(MemoryModel memoryModel)
Returns a mutable resizable copy of this array. |
java.lang.Class<? extends MutablePArray> |
mutableType()
Returns the canonical resizable AlgART type of arrays with the same element types: the class of one of 9 basic interfaces, describing all kinds of resizable AlgART arrays for 8 primitive and any non-primitive element types. |
java.lang.Class<? extends PArray> |
type()
Returns the canonical AlgART type of this array: the class of one of 9 basic interfaces, describing all kinds of AlgART arrays for 8 primitive and any non-primitive element types. |
UpdatablePArray |
updatableClone(MemoryModel memoryModel)
Returns an unresizable updatable copy of this array. |
java.lang.Class<? extends UpdatablePArray> |
updatableType()
Returns the canonical updatable AlgART type of arrays with the same element types: the class of one of 9 basic interfaces, describing all kinds of updatable AlgART arrays for 8 primitive and any non-primitive element types. |
| Methods inherited from interface net.algart.arrays.Array |
|---|
asCopyOnNextWrite, buffer, buffer, buffer, buffer, byteOrder, capacity, checkUnallowedMutation, elementType, equals, flushResources, flushResources, freeResources, freeResources, getData, getData, getElement, hashCode, isCopyOnNextWrite, isImmutable, isLazy, isNew, isNewReadOnlyView, isUnresizable, length, loadResources, newJavaArray, shallowClone, subArr, subArray, toString |
| Method Detail |
|---|
long bitsPerElement()
Array.capacity()*bitsPerElement()/8 bytes
(when the array capacity is large enough).
If the number of occupied bits is not defined (for example, may depend on JVM implementation), this method returns -1.
For implementations from this package, this method returns:
BitArray (the value of Arrays.BITS_PER_BIT constant),CharArray (the value of Arrays.BITS_PER_CHAR constant),ByteArray (the value of Arrays.BITS_PER_BYTE constant),ShortArray (the value of Arrays.BITS_PER_SHORT constant),IntArray (the value of Arrays.BITS_PER_INT constant),LongArray (the value of Arrays.BITS_PER_LONG constant),FloatArray (the value of Arrays.BITS_PER_FLOAT constant),DoubleArray (the value of Arrays.BITS_PER_DOUBLE constant).(-1 result is never returned by implementations from this package.)
Please keep in mind that the real amount of occupied memory, theoretically, can differ
from the value returned by this method.
For example, some JVM, theoretically, may store byte elements of byte[] array
in 32-bit memory words. In this case, this method will return invalid result for byte arrays
created by the simple memory model.
However: we guarantee the results of this method are always correct for arrays created
by the buffer memory model and large memory model.
There is a guarantee that this method works very quickly (usually it just returns a constant or a value of some private field).
Arrays.bitsPerElement(Class)double minPossibleValue(double valueForFloatingPoint)
BitArray, ByteArray, CharArray and ShortArray,
Integer.MIN_VALUE for IntArray,
Long.MIN_VALUE for LongArray,
valueForFloatingPoint for FloatArray and DoubleArray.
For fixed-point arrays it is the minimal possible value,
that can stored in elements of this array
(byte and short elements are interpreted as unsigned).
This method is equivalent to
minPossibleValue(thisArray.getClass(),
valueForFloatingPoint).
valueForFloatingPoint - the value returned for floating-point array type.PFixedArray.minPossibleValue()double maxPossibleValue(double valueForFloatingPoint)
BitArray,
0xFF for ByteArray,
0xFFFF for CharArray and ShortArray,
Integer.MAX_VALUE for IntArray,
Long.MAX_VALUE for LongArray,
valueForFloatingPoint for FloatArray and DoubleArray.
For fixed-point arrays it is the maximal possible value,
that can stored in elements of this array
(byte and short elements are interpreted as unsigned).
This method is equivalent to
maxPossibleValue(thisArray.getClass(),
valueForFloatingPoint).
valueForFloatingPoint - the value returned for floating-point array type.PFixedArray.maxPossibleValue()double getDouble(long index)
index - index of element to get.java.lang.IndexOutOfBoundsException - if index out of range 0..length()-1.UpdatablePArray.setDouble(long, double)
long indexOf(long lowIndex,
long highIndex,
double value)
length())
and getDouble(k)==value,
or -1 if there is no such array element.
In particular, if lowIndex>=thisArray.length()}
or lowIndex>=highIndex, this method returns -1,
and if lowIndex<0, the result is the same as if lowIndex==0.
You may specify lowIndex=0 and highIndex=Long.MAX_VALUE to search through all array elements.
lowIndex - the low index in the array for search (inclusive).highIndex - the high index in the array for search (exclusive).value - the value to be found.
long lastIndexOf(long lowIndex,
long highIndex,
double value)
getDouble(k)==value,
or -1 if there is no such array element.
In particular, if highIndex<=0 or highIndex<=lowIndex,
this method returns -1,
and if highIndex>=thisArray.length(),
the result is the same as if highIndex==thisArray.length().
You may specify lowIndex=0 and highIndex=Long.MAX_VALUE to search through all array elements.
lowIndex - the low index in the array for search (inclusive).highIndex - the high index in the array for search (exclusive).value - the value to be found.boolean isZeroFilled()
For arrays of floating-point types (PFloatingArray),
this method considers that +0.0==-0.0: both values are considered to be zero.
If the length of this array is 0 (the array is empty), returns true.
This method usually requires some time for execution, because it checks all array elements.
java.lang.Class<? extends PArray> type()
ArrayBitArray.class, if this object is an instance of BitArray,CharArray.class, if this object is an instance of CharArray,ByteArray.class, if this object is an instance of ByteArray,ShortArray.class, if this object is an instance of ShortArray,IntArray.class, if this object is an instance of IntArray,LongArray.class, if this object is an instance of LongArray,FloatArray.class, if this object is an instance of FloatArray,DoubleArray.class, if this object is an instance of DoubleArray,ObjectArray.class, if this object is an instance of ObjectArray.There is a guarantee that this method works very quickly (usually it just returns a constant value).
type in interface Arrayjava.lang.Class<? extends UpdatablePArray> updatableType()
ArrayUpdatableBitArray.class, if this object is an instance of BitArray,UpdatableCharArray.class, if this object is an instance of CharArray,UpdatableByteArray.class, if this object is an instance of ByteArray,UpdatableShortArray.class, if this object is an instance of ShortArray,UpdatableIntArray.class, if this object is an instance of IntArray,UpdatableLongArray.class, if this object is an instance of LongArray,UpdatableFloatArray.class, if this object is an instance of FloatArray,UpdatableDoubleArray.class, if this object is an instance of DoubleArray,UpdatableObjectArray.class, if this object is an instance of ObjectArray.There is a guarantee that this method works very quickly (usually it just returns a constant value).
updatableType in interface Arrayjava.lang.Class<? extends MutablePArray> mutableType()
ArrayMutableBitArray.class, if this object is an instance of BitArray,MutableCharArray.class, if this object is an instance of CharArray,MutableByteArray.class, if this object is an instance of ByteArray,MutableShortArray.class, if this object is an instance of ShortArray,MutableIntArray.class, if this object is an instance of IntArray,MutableLongArray.class, if this object is an instance of LongArray,MutableFloatArray.class, if this object is an instance of FloatArray,MutableDoubleArray.class, if this object is an instance of DoubleArray,MutableObjectArray.class, if this object is an instance of ObjectArray.There is a guarantee that this method works very quickly (usually it just returns a constant value).
mutableType in interface ArrayPArray asImmutable()
ArrayArray.isImmutable() is true),
returns a reference to this object.
A array is considered to be immutable,
if there are no ways to modify its content or state with help of this instance.
In particular, immutable arrays never
implement UpdatableArray or DirectAccessible interfaces.
Moreover, any third-party implementation of Array interface
must return an instance of a class, which has no public methods or fields
allowing to change this instance.
Query operations on the returned array "read through"
to this array. The returned view is also unresizable
(see UpdatableArray.asUnresizable()).
The returned view (when it is not a reference to this object) contains the same elements
as this array, but independent length, start offset, capacity, copy-on-next-write and
possible other information about array characteristics besides its elements,
as for Array.shallowClone() method.
If modifications of this array characteristics lead to reallocation
of the internal storage, then the returned array ceases to be a view of this array.
The only possible reasons for reallocation are the following:
calling MutableArray.length(long),
MutableArray.ensureCapacity(long) or MutableArray.trim() methods
for this array, or any modification of this or returned array in a case when
this array is copy-on-next-write.
By default, the array factories (memory models) create mutable arrays,
but they can be converted to immutable by this method.
Note: Array.isNew() method, called for the result of this method, always returns false
— because it does not implement UpdatableArray.
Also note: Array.isNewReadOnlyView() method, called for the result of this method, always returns
the same value as Array.isNewReadOnlyView() for this object.
Really,
Array.isImmutable()==true),
then it is obvious (this method just returns a reference to this array);Array.isImmutable()==false),
then, according to the contract to Array.isNewReadOnlyView() method,
Array.isNewReadOnlyView() must return false for this array
(in other case Array.isImmutable() would return true) and
it also must return false for the returned array
(because it is a view of another array and not an original view of external data —
see the beginning of the comment to Array.isNewReadOnlyView()).
asImmutable in interface ArrayArray.isImmutable(),
Array.asTrustedImmutable(),
Array.mutableClone(MemoryModel),
Array.updatableClone(MemoryModel),
UpdatableArray.asUnresizable()PArray asTrustedImmutable()
ArrayA array is considered to be "trusted" immutable,
if it potentially can change its elements,
but the Java code working with this array promises that it will not change them.
The returned instance never implements UpdatableArray,
but may implement DirectAccessible, that allow quick access to its elements.
As for usual immutable view,
query operations on the returned array "read through"
to this array.
The only standard way allowing to change elements of returned array
is using DirectAccessible.javaArray() method, in a case when the array is backed
by an accessible array.
But the Java code, processing the trusted immutable array,
must use this method only for quick reading elements and not try to change them.
If, despite the promise, the elements of the trusted immutable array will be changed,
the UnallowedMutationError may be thrown by the call of
Array.checkUnallowedMutation() method.
In some implementations — for example, if DirectAccessible
interface is not supported by this array
— this method may return the same result as Array.asImmutable().
The returned view is always unresizable.
The returned view (when it is not a reference to this object) contains the same elements
as this array, but independent length, start offset, capacity, copy-on-next-write and
possible other information about array characteristics besides its elements,
as for Array.shallowClone() method.
If modifications of this array characteristics lead to reallocation
of the internal storage, then the returned array ceases to be a view of this array.
The only possible reasons for reallocation are the following:
calling MutableArray.length(long),
MutableArray.ensureCapacity(long) or MutableArray.trim() methods
for this array, or any modification of this or returned array in a case when
this array is copy-on-next-write.
Trusted immutable view is a compromise between absolute safety, provided by
usual immutable view, and maximal efficiency,
achieved while using the original non-protected array.
Please see the package description
to learn more about possible usage of this method.
asTrustedImmutable in interface ArrayArray.asImmutable(),
Array.checkUnallowedMutation()MutablePArray mutableClone(MemoryModel memoryModel)
ArraymemoryModel.newArray(thisArray).copy(thisArray);
Please note: this method is a good choice for cloning little arrays (thousands, maybe millions elements). If you clone large arrays by this method, the user, in particular, has no ways to view the progress of copying or to interrupt copying. To clone large arrays, we recommend the following code:
MutableArray clone = memoryModel.newArray(thisArray);Arrays.copy(someContext, clone, a);
mutableClone in interface ArraymemoryModel - the memory model, used for allocation a new copy of this array.Array.updatableClone(MemoryModel)UpdatablePArray updatableClone(MemoryModel memoryModel)
ArraymemoryModel.newUnresizableArray(thisArray).copy(thisArray);
Please note: this method is a good choice for cloning little arrays (thousands, maybe millions elements). If you clone large arrays by this method, the user, in particular, has no ways to view the progress of copying or to interrupt copying. To clone large arrays, we recommend the following code:
UpdatableArray clone = memoryModel.newUnresizableArray(thisArray);Arrays.copy(someContext, clone, a);
updatableClone in interface ArraymemoryModel - the memory model, used for allocation a new copy of this array.Array.mutableClone(MemoryModel)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||