Interface CombinedMemoryModel.Combiner<E>
- All Known Subinterfaces:
CombinedMemoryModel.BufferedCombiner<E>
,CombinedMemoryModel.CombinerInPlace<E>
- All Known Implementing Classes:
CombinedMemoryModel.AbstractByteBufferCombiner
,CombinedMemoryModel.AbstractByteBufferCombinerInPlace
- Enclosing class:
CombinedMemoryModel<E>
This interface should be implemented to allow saving objects
in arrays created via combined memory model
.
It describes how to store (or load) one object in (from) a set of AlgART arrays. More precisely, this interface should provide methods for storing and loading all data of one object (an element of a combined array) in/from several "parallel" AlgART arrays, named "storage". An element with given index should be stored in the following elements in storage:
storage[k][d[k]*index...d[k]*(index+1)-1], k=0,1,...where d is an array returned by
numbersOfElementsPerOneCombinedElement(int)
method.
Important! The classes of objects stored or loaded by this combiner should have correct hashCode method, based on the content of an object: the data stored or loaded by this combiner. See also comments to CombinedMemoryModel.
Typical implementation supposes that a storage is one or several arrays of primitive types
(created by SimpleMemoryModel
).
The methods of this interface may not check indexes of elements:
all necessary checks are performed by AlgART array implementation created by CombinedMemoryModel
.
-
Method Summary
Modifier and TypeMethodDescriptionallocateStorage
(long length, boolean unresizable) Should create a storage (several AlgART arrays), allowing to store elements of the combined arrays.Returns an element #index of the combined array from the given set of AlgART arrays.int
numbersOfElementsPerOneCombinedElement
(int indexOfArrayInStorage) Should return the number of sequential elements of the array #indexOfArrayInStorage in the storage, used for storing one element of the combined array.void
set
(long index, E value, UpdatableArray[] storage) Stores the element value at position #index of the combined array inside the given set of AlgART arrays.
-
Method Details
-
get
Returns an element #index of the combined array from the given set of AlgART arrays. UnlikeCombinedMemoryModel.CombinerInPlace.getInPlace(long, Object, Array[])
, this method always creates a new object and should work always. This method is called byArray.getElement(long)
.- Parameters:
index
- an index in the combined array.storage
- a set of arrays where the retrieved content is stored now.- Returns:
- new created object containing an element #index of combined array.
-
set
Stores the element value at position #index of the combined array inside the given set of AlgART arrays. This method is called byUpdatableArray.setElement(long, Object)
.Important: this method must not throw NullPointerException if the value argument is null. Instead, it should store some "signal" value in the storage, that cannot be stored for any possible non-null elements, or just some default ("empty") value. In the first case, further
get(index, storage)
should return null; in the second case, it should return an instance in the default state.- Parameters:
index
- an index in the combined array.value
- the stored elementstorage
- a set of arrays where the content will be stored.
-
allocateStorage
Should create a storage (several AlgART arrays), allowing to store elements of the combined arrays. Called while creating new combined arrays.The initial lengths of created arrays should be calculated on the base of passed length argument, that means the length of necessary combined array. Namely, the length of returned array #k should be equal to length*
numbersOfElementsPerOneCombinedElement
(k). This condition is automatically verified while creating combined arrays.If unresizable argument is true, it means that this method is called for creating
unresizable
combined array. In this case we recommend to useMemoryModel.newUnresizableArray
method for creating storage arrays. If unresizable argument is false, every element of returned Java array must implementMutableArray
interface.- Parameters:
length
- initial length of corresponding combined arrays.unresizable
- if true, the created arrays should be unresizable, in other case they must be mutable and implementMutableArray
interface.- Returns:
- created storage.
-
numbersOfElementsPerOneCombinedElement
int numbersOfElementsPerOneCombinedElement(int indexOfArrayInStorage) Should return the number of sequential elements of the array #indexOfArrayInStorage in the storage, used for storing one element of the combined array. Called while creating new combined arrays.- Parameters:
indexOfArrayInStorage
- index of the storage array.- Returns:
- the number of sequential elements used for storing one combined element.
-