Class CompressedBitMatrix<R,​C>

    • Field Detail

      • BIT1

        public static long BIT1
      • BITS_PER_ELEMENT

        public static int BITS_PER_ELEMENT
    • Constructor Detail

      • CompressedBitMatrix

        public CompressedBitMatrix​(int rows,
                                   int cols,
                                   int totalBitsPerItem)
        Constructs a matrix with specified rows, columns, and total bits per cell

        Implementation note: this is created by maintaining one or more Double matrices; the Doubles are used as bit fields.

        Parameters:
        rows - - number of rows in the matrix
        cols - - number of columns in the matrix
        totalBitsPerItem - - the number of bits for each cell
    • Method Detail

      • bitCount

        public int bitCount​(int r,
                            int c)
        Count the number of one-bits at the specified cell position
        Parameters:
        r -
        c -
        Returns:
      • columns

        public int columns()
        Description copied from interface: Matrix2D
        Get the number of columns the matrix has.
        Specified by:
        columns in interface Matrix2D<R,​C,​double[]>
        Returns:
        int
      • get

        public double[] get​(int row,
                            int col)
        Specified by:
        get in interface ObjectMatrix<R,​C,​double[]>
      • get

        public boolean get​(int row,
                           int col,
                           int index)
        Checks the bit of the specified cell at the specified index.
        Parameters:
        row - - matrix row
        col - - matrix column
        index - - bit vector index
        Returns:
        true if bit is 1, false if 0.
      • getAllBits

        public long[] getAllBits​(int row,
                                 int col)
        Returns all of the bits for a cell
        Parameters:
        row - - the cell row
        col - - the cell column
        Returns:
        all the bits encoded as an array of longs
      • getBitNum

        public int getBitNum()
        Returns the total number of bits in a matrix cell
        Returns:
        the number of bits per cell
      • getByKeys

        public double[] getByKeys​(R r,
                                  C c)
        Specified by:
        getByKeys in interface Matrix2D<R,​C,​double[]>
      • getColumn

        public double[][] getColumn​(int i)
        Specified by:
        getColumn in interface ObjectMatrix<R,​C,​double[]>
      • getEntry

        public double[] getEntry​(int row,
                                 int column)
        Specified by:
        getEntry in interface Matrix2D<R,​C,​double[]>
        Returns:
      • getRow

        public double[][] getRow​(int i)
        Specified by:
        getRow in interface ObjectMatrix<R,​C,​double[]>
      • getRowBitCount

        public int[] getRowBitCount​(int row)
        Parameters:
        row -
        Returns:
        - array of counts of one-bits for each cell in the row.
      • isMissing

        public boolean isMissing​(int i,
                                 int j)
        Description copied from interface: Matrix2D
        Check if the value at a given index is missing.
        Specified by:
        isMissing in interface Matrix2D<R,​C,​double[]>
        Parameters:
        i - row
        j - column
        Returns:
        true if the value is missing, false otherwise.
      • overlap

        public int overlap​(int row1,
                           int col1,
                           int row2,
                           int col2)
        Counts the number of one-bits that are in common between the two specified cells; i.e. performs an AND operation on the two bit vectors and counts the remaining 1 bits.
        Parameters:
        row1 - - cell 1 row
        col1 - - cell 1 column
        row2 - - cell 2 row
        col2 - - cell 2 column
        Returns:
        number of bits in common
      • reset

        public void reset​(int r,
                          int c)
      • rows

        public int rows()
        Description copied from interface: Matrix2D
        Get the number of rows the matrix has
        Specified by:
        rows in interface Matrix2D<R,​C,​double[]>
        Returns:
        int
      • set

        public void set​(int row,
                        int col,
                        double[] val)
        Set the matrix cell to the specified bit vector
        Specified by:
        set in interface Matrix2D<R,​C,​double[]>
        Parameters:
        row -
        col -
        val -
      • set

        public void set​(int row,
                        int col,
                        int index)
        Sets the bit of the specified cell at the specified index to 1.
        Parameters:
        row - - matrix row
        col - - matrix column
        index - - bit vector index
      • setByKeys

        public void setByKeys​(R r,
                              C c,
                              double[] v)
        Specified by:
        setByKeys in interface Matrix2D<R,​C,​double[]>
      • subset

        public ObjectMatrix<R,​C,​double[]> subset​(int startRow,
                                                             int startCol,
                                                             int numRow,
                                                             int numCol)
        Specified by:
        subset in interface ObjectMatrix<R,​C,​double[]>
        Returns:
      • toFile

        public void toFile​(String fileName)
                    throws IOException
        Save the matrix to the specified file
        Parameters:
        fileName - - save file
        Throws:
        IOException
      • totalBitCount

        public long totalBitCount()
        Number of ones in the entire matrix.
        Returns:
      • unset

        public void unset​(int row,
                          int col,
                          int index)