Class SelectedSparseObjectMatrix1D

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    class SelectedSparseObjectMatrix1D
    extends ObjectMatrix1D
    Selection view on sparse 1-d matrices holding Object elements. First see the package summary and javadoc tree view to get the broad picture.

    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 Detail

      • offsets

        protected int[] offsets
        The offsets of visible indexes of this matrix.
      • offset

        protected int offset
        The offset.
    • Constructor Detail

      • 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

        protected SelectedSparseObjectMatrix1D​(AbstractIntObjectMap elements,
                                               int[] offsets)
        Constructs a matrix view with the given parameters.
        Parameters:
        elements - the cells.
        indexes - The indexes of the cells that shall be visible.
    • Method Detail

      • _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 class AbstractMatrix1D
        Parameters:
        rank - the absolute rank of the element.
        Returns:
        the position.
      • getQuick

        public java.lang.Object getQuick​(int index)
        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 class ObjectMatrix1D
        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 class AbstractMatrix1D
        Parameters:
        rank - the rank of the element.
      • like

        public ObjectMatrix1D like​(int size)
        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 class ObjectMatrix1D
        Parameters:
        size - the number of cell the matrix shall have.
        Returns:
        a new empty matrix of the same dynamic type.
      • like2D

        public ObjectMatrix2D like2D​(int rows,
                                     int columns)
        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 class ObjectMatrix1D
        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

        public void setQuick​(int index,
                             java.lang.Object value)
        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 class ObjectMatrix1D
        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 class AbstractMatrix1D
        Parameters:
        size - the number of cells the matrix shall have.
      • viewSelectionLike

        protected ObjectMatrix1D viewSelectionLike​(int[] offsets)
        Construct and returns a new selection view.
        Specified by:
        viewSelectionLike in class ObjectMatrix1D
        Parameters:
        offsets - the offsets of the visible elements.
        Returns:
        a new view.