Class SelectedSparseObjectMatrix1D
- All Implemented Interfaces:
Serializable
,Cloneable
Implementation:
Objects of this class are typically constructed via viewIndexes methods on some source matrix. The interface introduced in abstract super classes defines everything a user can do. From a user point of view there is nothing special about this class; it presents the same functionality with the same signatures and semantics as its abstract superclass(es) while introducing no additional functionality. Thus, this class need not be visible to users. By the way, the same principle applies to concrete DenseXXX, SparseXXX classes: they presents the same functionality with the same signatures and semantics as abstract superclass(es) while introducing no additional functionality. Thus, they need not be visible to users, either. Factory methods could hide all these concrete types.
This class uses no delegation. Its instances point directly to the data. Cell addressing overhead is 1 additional array index access per get/set.
Note that this implementation is not synchronized.
Memory requirements:
memory [bytes] = 4*indexes.length. Thus, an index view with 1000 indexes additionally uses 4 KB.
Time complexity:
Depends on the parent view holding cells.
- Version:
- 1.0, 09/24/99
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AbstractIntObjectMap
protected int
The offset.protected int[]
The offsets of visible indexes of this matrix.Fields inherited from class cern.colt.matrix.impl.AbstractMatrix1D
size, stride, zero
Fields inherited from class cern.colt.matrix.impl.AbstractMatrix
isNoView
Fields inherited from class cern.colt.PersistentObject
serialVersionUID
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SelectedSparseObjectMatrix1D
(int size, AbstractIntObjectMap elements, int zero, int stride, int[] offsets, int offset) Constructs a matrix view with the given parameters.protected
SelectedSparseObjectMatrix1D
(AbstractIntObjectMap elements, int[] offsets) Constructs a matrix view with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
_offset
(int absRank) Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array.getQuick
(int index) Returns the matrix cell value at coordinate index.protected boolean
haveSharedCellsRaw
(ObjectMatrix1D other) Returns true if both matrices share at least one identical cell.protected int
index
(int rank) Returns the position of the element with the given relative rank within the (virtual or non-virtual) internal 1-dimensional array.like
(int size) Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified size.like2D
(int rows, int columns) Construct and returns a new 2-d matrix of the corresponding dynamic type, entirelly independent of the receiver.void
Sets the matrix cell at coordinate index to the specified value.protected void
setUp
(int size) Sets up a matrix with a given number of cells.protected ObjectMatrix1D
viewSelectionLike
(int[] offsets) Construct and returns a new selection view.Methods inherited from class cern.colt.matrix.ObjectMatrix1D
aggregate, aggregate, assign, assign, assign, assign, assign, cardinality, copy, equals, equals, get, getContent, getNonZeros, haveSharedCells, like, set, swap, toArray, toArray, toString, view, viewFlip, viewPart, viewSelection, viewSelection, viewSorted, viewStrides
Methods inherited from class cern.colt.matrix.impl.AbstractMatrix1D
_rank, checkIndex, checkIndexes, checkRange, checkSize, checkSize, setUp, size, stride, toStringShort, vFlip, vPart, vStrides
Methods inherited from class cern.colt.matrix.impl.AbstractMatrix
ensureCapacity, isView, trimToSize
Methods inherited from class cern.colt.PersistentObject
clone
-
Field Details
-
elements
-
offsets
protected int[] offsetsThe offsets of visible indexes of this matrix. -
offset
protected int offsetThe offset.
-
-
Constructor Details
-
SelectedSparseObjectMatrix1D
protected SelectedSparseObjectMatrix1D(int size, AbstractIntObjectMap elements, int zero, int stride, int[] offsets, int offset) Constructs a matrix view with the given parameters.- Parameters:
size
- the number of cells the matrix shall have.elements
- the cells.zero
- the index of the first element.stride
- the number of indexes between any two elements, i.e. index(i+1)-index(i).offsets
- the offsets of the cells that shall be visible.offset
-
-
SelectedSparseObjectMatrix1D
Constructs a matrix view with the given parameters.- Parameters:
elements
- the cells.indexes
- The indexes of the cells that shall be visible.
-
-
Method Details
-
_offset
protected int _offset(int absRank) Returns the position of the given absolute rank within the (virtual or non-virtual) internal 1-dimensional array. Default implementation. Override, if necessary.- Overrides:
_offset
in classAbstractMatrix1D
- Parameters:
rank
- the absolute rank of the element.- Returns:
- the position.
-
getQuick
Returns the matrix cell value at coordinate index.Provided with invalid parameters this method may return invalid objects without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): index<0 || index>=size().
- Specified by:
getQuick
in classObjectMatrix1D
- Parameters:
index
- the index of the cell.- Returns:
- the value of the specified cell.
-
index
protected int index(int rank) Returns the position of the element with the given relative rank within the (virtual or non-virtual) internal 1-dimensional array. You may want to override this method for performance.- Overrides:
index
in classAbstractMatrix1D
- Parameters:
rank
- the rank of the element.
-
like
Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified size. For example, if the receiver is an instance of type DenseObjectMatrix1D the new matrix must also be of type DenseObjectMatrix1D, if the receiver is an instance of type SparseObjectMatrix1D the new matrix must also be of type SparseObjectMatrix1D, etc. In general, the new matrix should have internal parametrization as similar as possible.- Specified by:
like
in classObjectMatrix1D
- Parameters:
size
- the number of cell the matrix shall have.- Returns:
- a new empty matrix of the same dynamic type.
-
like2D
Construct and returns a new 2-d matrix of the corresponding dynamic type, entirelly independent of the receiver. For example, if the receiver is an instance of type DenseObjectMatrix1D the new matrix must be of type DenseObjectMatrix2D, if the receiver is an instance of type SparseObjectMatrix1D the new matrix must be of type SparseObjectMatrix2D, etc.- Specified by:
like2D
in classObjectMatrix1D
- Parameters:
rows
- the number of rows the matrix shall have.columns
- the number of columns the matrix shall have.- Returns:
- a new matrix of the corresponding dynamic type.
-
setQuick
Sets the matrix cell at coordinate index to the specified value.Provided with invalid parameters this method may access illegal indexes without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): index<0 || index>=size().
- Specified by:
setQuick
in classObjectMatrix1D
- Parameters:
index
- the index of the cell.value
- the value to be filled into the specified cell.
-
setUp
protected void setUp(int size) Sets up a matrix with a given number of cells.- Overrides:
setUp
in classAbstractMatrix1D
- Parameters:
size
- the number of cells the matrix shall have.
-
viewSelectionLike
Construct and returns a new selection view.- Specified by:
viewSelectionLike
in classObjectMatrix1D
- Parameters:
offsets
- the offsets of the visible elements.- Returns:
- a new view.
-