|
AlgART Home | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.algart.arrays.AbstractMemoryModel
net.algart.arrays.SimpleMemoryModel
public final class SimpleMemoryModel extends AbstractMemoryModel
The simplest memory model, based on usual Java arrays.
It means that AlgART array of elements of some type
contains an underlying Java array type[],
and any access to AlgART array elements is translated
to corresponding access to the underlying Java array.
The only exception is bit arrays,
where the bits are packed into long[] Java array,
as specified in PackedBitArrays class.
This memory model supports all possible element types. The maximal theoretical limit for length and capacity of AlgART arrays, supported by this memory model, is 237-64 for bit arrays and 231-1 for all other element types. The real limit is essentially less, usually 2 GB in 64-bit JVM or ~1.0-1.5 GB in 32-bit JVM.
This memory model may be not effective enough for very large arrays of
non-primitive elements (inheritors of Object class):
it stores them as array of pointers, alike standard ArrayList.
For effective storing arrays of objects, we recommend using
the combined memory model.
All arrays created by this memory model, besides bit arrays and immutable views of the arrays, implement DirectAccessible interface,
and DirectAccessible.hasJavaArray() returns true for such arrays.
All arrays, created by this memory model, have empty implementation of
Array.loadResources(ArrayContext),
Array.flushResources(ArrayContext), Array.flushResources(ArrayContext, boolean) and
Array.freeResources(ArrayContext) methods:
these methods do nothing.
In the arrays of objects (non-primitive) created by this memory model:
ObjectInPlaceArray, UpdatableObjectInPlaceArray,
MutableObjectInPlaceArray interfaces are never implemented;UpdatableArray.copy(Array),
UpdatableArray.copy(long, long),
UpdatableArray.copy(long, long, long),
UpdatableArray.swap(UpdatableArray),
UpdatableArray.swap(long, long),
UpdatableArray.swap(long, long, long) methods
copies only references to objects, but do not perform deep cloning;Array.hashCode(), Array.equals(Object) methods
are based on implementation of hashCode and equals method
in the class of elements (Array.elementType()).This class is immutable and thread-safe:
there are no ways to modify settings of its instance returned by getInstance() method.
Moreover, it is a singleton: getInstance() always returns the same object.
AlgART Laboratory 2007-2013
| Modifier and Type | Method and Description | |
|---|---|---|
boolean |
areAllElementTypesSupported()
Returns true if this memory model can create arrays with all element types. |
|
boolean |
areAllPrimitiveElementTypesSupported()
Returns true if this memory model can create arrays with all primitive element types: boolean, char, byte, short, int, long, float, double. |
|
static UpdatableArray |
asUpdatableArray(java.lang.Object array)
Returns an unresizable AlgART array backed by the specified Java array, excluding a case of boolean[] array. |
|
static UpdatableByteArray |
asUpdatableByteArray(byte[] array)
Equivalent to (UpdatableByteArray) asUpdatableArray((Object)array). |
|
static UpdatableCharArray |
asUpdatableCharArray(char[] array)
Equivalent to (UpdatableCharArray) asUpdatableArray((Object)array). |
|
static UpdatableDoubleArray |
asUpdatableDoubleArray(double[] array)
Equivalent to (UpdatableDoubleArray) asUpdatableArray((Object)array). |
|
static UpdatableFloatArray |
asUpdatableFloatArray(float[] array)
Equivalent to (UpdatableFloatArray) asUpdatableArray((Object)array). |
|
static UpdatableIntArray |
asUpdatableIntArray(int[] array)
Equivalent to (UpdatableIntArray) asUpdatableArray((Object)array). |
|
static UpdatableLongArray |
asUpdatableLongArray(long[] array)
Equivalent to (UpdatableLongArray) asUpdatableArray((Object)array). |
|
static
|
asUpdatableObjectArray(E[] array)
Equivalent to (UpdatableObjectArray asUpdatableArray((Object)array) |
|
static UpdatableShortArray |
asUpdatableShortArray(short[] array)
Equivalent to (UpdatableShortArray) asUpdatableArray((Object)array). |
|
static SimpleMemoryModel |
getInstance()
Returns an instance of this memory model. |
|
boolean |
isCreatedBy(Array array)
Returns true if the passed array was created by this (or identical) memory model. |
|
boolean |
isElementTypeSupported(java.lang.Class<?> elementType)
Returns true if this memory model can create arrays with this element type. |
|
static boolean |
isSimpleArray(Array array)
Returns true if the passed instance is an array created by this memory model. |
|
long |
maxSupportedLength(java.lang.Class<?> elementType)
This implementation returns Integer.MAX_VALUE == 231-1 for all element types besides boolean.class, or some large value (depending on implementation) for boolean.class. |
|
MutableArray |
newArray(java.lang.Class<?> elementType,
long initialLength)
Constructs a zero-filled resizable array with the specified element type and initial length. |
|
MutableArray |
newEmptyArray(java.lang.Class<?> elementType)
Constructs an empty resizable array with the specified element type and a little initial capacity. |
|
MutableArray |
newEmptyArray(java.lang.Class<?> elementType,
long initialCapacity)
Constructs an empty resizable array with the specified element type and initial capacity. |
|
UpdatableArray |
newUnresizableArray(java.lang.Class<?> elementType,
long length)
Constructs a zero-filled unresizable array with the specified element type and length. |
|
java.lang.String |
toString()
Returns a brief string description of this memory model. |
|
UpdatableBitArray |
valueOf(boolean[] array)
Equivalent to (UpdatableBitArray) valueOf((Object)array). |
|
UpdatableBitArray |
valueOf(boolean[] array,
int offset,
int count)
Equivalent to (UpdatableBitArray) valueOf((Object)array, offset, count). |
|
UpdatableByteArray |
valueOf(byte[] array)
Equivalent to (UpdatableByteArray) valueOf((Object)array). |
|
UpdatableByteArray |
valueOf(byte[] array,
int offset,
int count)
Equivalent to (UpdatableByteArray) valueOf((Object)array, offset, count). |
|
UpdatableCharArray |
valueOf(char[] array)
Equivalent to (UpdatableCharArray) valueOf((Object)array). |
|
UpdatableCharArray |
valueOf(char[] array,
int offset,
int count)
Equivalent to (UpdatableCharArray) valueOf((Object)array, offset, count). |
|
UpdatableDoubleArray |
valueOf(double[] array)
Equivalent to (UpdatableDoubleArray) valueOf((Object)array). |
|
UpdatableDoubleArray |
valueOf(double[] array,
int offset,
int count)
Equivalent to (UpdatableDoubleArray) valueOf((Object)array, offset, count). |
|
UpdatableFloatArray |
valueOf(float[] array)
Equivalent to (UpdatableFloatArray) valueOf((Object)array). |
|
UpdatableFloatArray |
valueOf(float[] array,
int offset,
int count)
Equivalent to (UpdatableFloatArray) valueOf((Object)array, offset, count). |
|
UpdatableIntArray |
valueOf(int[] array)
Equivalent to (UpdatableIntArray) valueOf((Object)array). |
|
UpdatableIntArray |
valueOf(int[] array,
int offset,
int count)
Equivalent to (UpdatableIntArray) valueOf((Object)array, offset, count). |
|
UpdatableLongArray |
valueOf(long[] array)
Equivalent to (UpdatableLongArray) valueOf((Object)array). |
|
UpdatableLongArray |
valueOf(long[] array,
int offset,
int count)
Equivalent to (UpdatableLongArray) valueOf((Object)array, offset, count). |
|
UpdatableArray |
valueOf(java.lang.Object array)
Constructs an unresizable AlgART array containing all elements of the specified Java array: array[0], array[1], ..., array[array.length - 1]. |
|
UpdatableArray |
valueOf(java.lang.Object array,
int offset,
int count)
Constructs an unresizable AlgART array containing count elements of the specified Java array: array[offset], array[offset + 1], ..., array[offset + count - 1]. |
|
UpdatableShortArray |
valueOf(short[] array)
Equivalent to (UpdatableShortArray) valueOf((Object)array). |
|
UpdatableShortArray |
valueOf(short[] array,
int offset,
int count)
Equivalent to (UpdatableShortArray) valueOf((Object)array, offset, count). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public static SimpleMemoryModel getInstance()
Arrays.SMMpublic MutableArray newEmptyArray(java.lang.Class<?> elementType)
MemoryModelnewEmptyArray(elementType, n), where
n is some little value.
Example of usage:
MutableFloatArray a = (MutableFloatArray)memoryModel.newEmptyArray(float.class);
newEmptyArray in interface MemoryModelnewEmptyArray in class AbstractMemoryModelelementType - the type of array elements.MemoryModel.isElementTypeSupported(Class),
MemoryModel.newArray(Class, long)
public MutableArray newEmptyArray(java.lang.Class<?> elementType,
long initialCapacity)
MemoryModelThe element type can be either usual object class (as String.class), or one of the primitive types: boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class, char.class. The element type cannot be void.class.
In a case of primitive types, the created array
will implement the corresponding interface BitArray,
ByteArray, ShortArray, IntArray,
LongArray, FloatArray, DoubleArray or
CharArray. In this case, the created array
(unlike standard ArrayList) will occupy the same amount of memory
as the Java array boolean[initialCapacity], byte[initialCapacity], etc.
In a case of non-primitive types (Object inheritors), the created array
will implement the MutableObjectArray interface.
Some element type may be not supported by this memory model.
For example, some memory models may support only primitive types, or only one concrete type.
In such a case, UnsupportedElementTypeException will be thrown.
Some too large array capacities may be not supported by this memory model.
For example, SimpleMemoryModel does not support arrays larger than 0x7FFFFFFF
(Integer.MAX_VALUE) elements.
Example of usage:
MutableFloatArray a = (MutableFloatArray)memoryModel.newEmptyArray(float.class, 10000);
newEmptyArray in interface MemoryModelnewEmptyArray in class AbstractMemoryModelelementType - the type of array elements.initialCapacity - the initial capacity of the array.MemoryModel.isElementTypeSupported(Class),
MemoryModel.newArray(Class, long)
public MutableArray newArray(java.lang.Class<?> elementType,
long initialLength)
MemoryModelThis method is equivalent to the following call:
newEmptyArray(elementType, initialLength).length(initialLength).trim().
newArray in interface MemoryModelnewArray in class AbstractMemoryModelelementType - the type of array elements.initialLength - the initial length and capacity of the array.MemoryModel.isElementTypeSupported(Class),
MemoryModel.newEmptyArray(Class, long),
MemoryModel.newUnresizableArray(Class, long)
public UpdatableArray newUnresizableArray(java.lang.Class<?> elementType,
long length)
MemoryModelThe analogous result may be obtained the following call:
newArray(elementType, length).asUnresizable().
However, we don't recommend to use such code.
If you are sure that you will not need to change the array length,
please always use this method
(or newUnresizableBitArray,
newUnresizableBteArray, etc.).
In some memory models, creating resizable array with the given length
may require much more resources that creating unresizable one.
For example, in the large memory model
every resizable array is stored in the file consisting of integer number
of blocks per DataFileModel.recommendedBankSize(true) bytes.
newUnresizableArray in interface MemoryModelnewUnresizableArray in class AbstractMemoryModelelementType - the type of array elements.length - the length and capacity of the array.MemoryModel.isElementTypeSupported(Class),
MemoryModel.newArray(Class, long)
public UpdatableArray valueOf(java.lang.Object array,
int offset,
int count)
MemoryModelThe returned AlgART array will be "safe" in that no references to the passed Java array are maintained by it. In other words, this method must always allocate a new AlgART array.
This method is equivalent to the following expression:
newUnresizableArray(elementType, count).setData(0, array, offset, count),
where elementType is the type of array elements
(array.getClass().getComponentType()).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.offset - starting position in the source Java array.count - the length of returned AlgART array.public UpdatableArray valueOf(java.lang.Object array)
MemoryModelThe returned AlgART array will be "safe" in that no references to the passed Java array are maintained by it. In other words, this method must always allocate a new array.
This method is equivalent to the following expression:
newUnresizableArray(elementType, len).setData(0, array),
where elementType is the type of array elements
(array.getClass().getComponentType()) and
len is the length of the passed Java array.
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.
public UpdatableBitArray valueOf(boolean[] array,
int offset,
int count)
MemoryModelvalueOf((Object)array, offset, count).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.offset - starting position in the source Java array.count - the length of returned AlgART array.public UpdatableBitArray valueOf(boolean[] array)
MemoryModelvalueOf((Object)array).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.
public UpdatableCharArray valueOf(char[] array,
int offset,
int count)
MemoryModelvalueOf((Object)array, offset, count).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.offset - starting position in the source Java array.count - the length of returned AlgART array.public UpdatableCharArray valueOf(char[] array)
MemoryModelvalueOf((Object)array).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.
public UpdatableByteArray valueOf(byte[] array,
int offset,
int count)
MemoryModelvalueOf((Object)array, offset, count).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.offset - starting position in the source Java array.count - the length of returned AlgART array.public UpdatableByteArray valueOf(byte[] array)
MemoryModelvalueOf((Object)array).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.
public UpdatableShortArray valueOf(short[] array,
int offset,
int count)
MemoryModelvalueOf((Object)array, offset, count).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.offset - starting position in the source Java array.count - the length of returned AlgART array.public UpdatableShortArray valueOf(short[] array)
MemoryModelvalueOf((Object)array).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.
public UpdatableIntArray valueOf(int[] array,
int offset,
int count)
MemoryModelvalueOf((Object)array, offset, count).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.offset - starting position in the source Java array.count - the length of returned AlgART array.public UpdatableIntArray valueOf(int[] array)
MemoryModelvalueOf((Object)array).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.
public UpdatableLongArray valueOf(long[] array,
int offset,
int count)
MemoryModelvalueOf((Object)array, offset, count).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.offset - starting position in the source Java array.count - the length of returned AlgART array.public UpdatableLongArray valueOf(long[] array)
MemoryModelvalueOf((Object)array).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.
public UpdatableFloatArray valueOf(float[] array,
int offset,
int count)
MemoryModelvalueOf((Object)array, offset, count).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.offset - starting position in the source Java array.count - the length of returned AlgART array.public UpdatableFloatArray valueOf(float[] array)
MemoryModelvalueOf((Object)array).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.
public UpdatableDoubleArray valueOf(double[] array,
int offset,
int count)
MemoryModelvalueOf((Object)array, offset, count).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.offset - starting position in the source Java array.count - the length of returned AlgART array.public UpdatableDoubleArray valueOf(double[] array)
MemoryModelvalueOf((Object)array).
valueOf in interface MemoryModelvalueOf in class AbstractMemoryModelarray - the source Java array with elements of constructed AlgART array.public boolean isElementTypeSupported(java.lang.Class<?> elementType)
MemoryModelUnsupportedElementTypeException.
The result is not defined for void.class.
isElementTypeSupported in interface MemoryModelisElementTypeSupported in class AbstractMemoryModelelementType - the type of array elements.public boolean areAllPrimitiveElementTypesSupported()
MemoryModel
areAllPrimitiveElementTypesSupported in interface MemoryModelareAllPrimitiveElementTypesSupported in class AbstractMemoryModelMemoryModel.isElementTypeSupported(Class)public boolean areAllElementTypesSupported()
MemoryModelSimpleMemoryModel.
areAllElementTypesSupported in interface MemoryModelareAllElementTypesSupported in class AbstractMemoryModelMemoryModel.isElementTypeSupported(Class)public long maxSupportedLength(java.lang.Class<?> elementType)
In current implementation, returns 237-64 for boolean.class, because bits are stored in long values.
maxSupportedLength in interface MemoryModelmaxSupportedLength in class AbstractMemoryModelelementType - the type of array elements.java.lang.NullPointerException - if elementType is null.public boolean isCreatedBy(Array array)
MemoryModelFor SimpleMemoryModel and BufferMemoryModel,
"identical" means the same memory model.
For LargeMemoryModel, "identical" means that
the memory model is also large and was created with
the same instance of the data file factory.
For CombinedMemoryModel, "identical" means that
the memory model is also combined and was created with
the same instance of the combiner.
Returns false if the passed argument is null.
isCreatedBy in interface MemoryModelisCreatedBy in class AbstractMemoryModelarray - the AlgART array (may be null, than the method returns false).public static boolean isSimpleArray(Array array)
As this memory model is a singleton, this method is equivalent to isCreatedBy(Array).
array - the checked array.public java.lang.String toString()
The result of this method may depend on implementation.
toString in class java.lang.Objectpublic static UpdatableArray asUpdatableArray(java.lang.Object array)
array - the source Java array.java.lang.NullPointerException - if array argument is null.java.lang.IllegalArgumentException - if array argument is not an array
or boolean[] array.public static UpdatableCharArray asUpdatableCharArray(char[] array)
asUpdatableArray((Object)array).
array - the source Java array.java.lang.NullPointerException - if array argument is null.public static UpdatableByteArray asUpdatableByteArray(byte[] array)
asUpdatableArray((Object)array).
array - the source Java array.java.lang.NullPointerException - if array argument is null.public static UpdatableShortArray asUpdatableShortArray(short[] array)
asUpdatableArray((Object)array).
array - the source Java array.java.lang.NullPointerException - if array argument is null.public static UpdatableIntArray asUpdatableIntArray(int[] array)
asUpdatableArray((Object)array).
array - the source Java array.java.lang.NullPointerException - if array argument is null.public static UpdatableLongArray asUpdatableLongArray(long[] array)
asUpdatableArray((Object)array).
array - the source Java array.java.lang.NullPointerException - if array argument is null.public static UpdatableFloatArray asUpdatableFloatArray(float[] array)
asUpdatableArray((Object)array).
array - the source Java array.java.lang.NullPointerException - if array argument is null.public static UpdatableDoubleArray asUpdatableDoubleArray(double[] array)
asUpdatableArray((Object)array).
array - the source Java array.java.lang.NullPointerException - if array argument is null.public static <E> UpdatableObjectArray<E> asUpdatableObjectArray(E[] array)
asUpdatableArray((Object)array)
array - the source Java array.java.lang.NullPointerException - if array argument is null.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||