coreEngine.Helper.CompressArray

## Class CA2DFloat

- java.lang.Object
- - coreEngine.Helper.CompressArray.CA2DFloat

- All Implemented Interfaces:
    java.io.Serializable

      public class CA2DFloat
      extends java.lang.Object
      implements java.io.Serializable

  Compressed 2-D float array (line compression version). This array cost same amount of memory at runtime, but is compressed in serialization. This class provides several utility functions for changing value in the array. Ideal when the data in the array is well organized.
  Author:
    Shu Liu
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private float[][]` | `fullMatrix` 2D array contains the full matrix
    `private float[]` | `lineNum` Array of unique numbers for compression
    `private int[]` | `lineRep` Array of number of repetitions for compression
    `private static long` | `serialVersionUID` serialVersionUID
    `private int` | `sizeX` Number of rows
    `private int` | `sizeY` Number of columns

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CA2DFloat(int sizeX, int sizeY, float defaultValue)` Constructor of compress 2D array

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(float value, int x, int y)` Add a value to a single location in the array
    `void` | `add(float value, int fromX, int fromY, int toX, int toY)` Add a value to a region in the array
    `void` | `addColumn(int beforeColumn, int numColumns, float defaultValue)` Add one or more columns to array
    `void` | `addRow(int beforeRow, int numRows, float defaultValue)` Add one or more rows to array
    `private void` | `compressMatrix()` Prepare compressed data from full matrix to write out
    `void` | `deepCopyFrom(CA2DFloat matrix)` Initialize a compressed matrix by creating a deep copy
    `private void` | `expandMatrix()` Expand compressed data to full matrix
    `float` | `get(int x, int y)` Get a single value from the array
    `int` | `getSizeX()` Getter for number of rows
    `int` | `getSizeY()` Getter for the number of columns
    `void` | `multiply(float value, int x, int y)` Multiply a value to a single location in the array
    `void` | `multiply(float value, int fromX, int fromY, int toX, int toY)` Multiply a value to a region in the array
    `private void` | `readObject(java.io.ObjectInputStream in)` Read object from input stream
    `void` | `removeColumn(int column)` Remove a single column from array
    `void` | `removeColumn(int fromColumn, int toColumn)` Remove multiple columns from array
    `void` | `removeRow(int row)` Remove a single row from array
    `void` | `removeRow(int fromRow, int toRow)` Remove multiple rows from array
    `void` | `set(float value, int x, int y)` Set a value to a single location in the array
    `void` | `set(float value, int fromX, int fromY, int toX, int toY)` Set a value to a region in the array
    `private void` | `writeObject(java.io.ObjectOutputStream out)` Write object to output stream

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### serialVersionUID

          private static final long serialVersionUID

      serialVersionUID
      See Also:
        Constant Field Values

    - #### sizeX

          private int sizeX

      Number of rows

    - #### sizeY

          private int sizeY

      Number of columns

    - #### fullMatrix

          private float[][] fullMatrix

      2D array contains the full matrix

    - #### lineNum

          private float[] lineNum

      Array of unique numbers for compression

    - #### lineRep

          private int[] lineRep

      Array of number of repetitions for compression

  - ### Constructor Detail

    - #### CA2DFloat

          public CA2DFloat(int sizeX,
                           int sizeY,
                           float defaultValue)

      Constructor of compress 2D array
      Parameters:
        `sizeX` - Number of rows
        `sizeY` - Number of columns
        `defaultValue` - Default value in the array

  - ### Method Detail

    - #### set

          public void set(float value,
                          int x,
                          int y)

      Set a value to a single location in the array
      Parameters:
        `value` - new value
        `x` - row index
        `y` - column index

    - #### set

          public void set(float value,
                          int fromX,
                          int fromY,
                          int toX,
                          int toY)

      Set a value to a region in the array
      Parameters:
        `value` - new value
        `fromX` - from row index (inclusive)
        `fromY` - from column index (inclusive)
        `toX` - to row index (inclusive)
        `toY` - to column index (inclusive)

    - #### add

          public void add(float value,
                          int x,
                          int y)

      Add a value to a single location in the array
      Parameters:
        `value` - value to be added
        `x` - row index
        `y` - column index

    - #### add

          public void add(float value,
                          int fromX,
                          int fromY,
                          int toX,
                          int toY)

      Add a value to a region in the array
      Parameters:
        `value` - value to be added
        `fromX` - from row index (inclusive)
        `fromY` - from column index (inclusive)
        `toX` - to row index (inclusive)
        `toY` - to column index (inclusive)

    - #### multiply

          public void multiply(float value,
                               int x,
                               int y)

      Multiply a value to a single location in the array
      Parameters:
        `value` - value to be multiplied
        `x` - row index
        `y` - column index

    - #### multiply

          public void multiply(float value,
                               int fromX,
                               int fromY,
                               int toX,
                               int toY)

      Multiply a value to a region in the array
      Parameters:
        `value` - value to be multiplied
        `fromX` - from row index (inclusive)
        `fromY` - from column index (inclusive)
        `toX` - to row index (inclusive)
        `toY` - to column index (inclusive)

    - #### addRow

          public void addRow(int beforeRow,
                             int numRows,
                             float defaultValue)

      Add one or more rows to array
      Parameters:
        `beforeRow` - row index before which new rows to be added
        `numRows` - number of new rows to be added
        `defaultValue` - default value for new added rows

    - #### addColumn

          public void addColumn(int beforeColumn,
                                int numColumns,
                                float defaultValue)

      Add one or more columns to array
      Parameters:
        `beforeColumn` - column index before which new columns to be added
        `numColumns` - number of new columns to be added
        `defaultValue` - default value for new added columns

    - #### removeRow

          public void removeRow(int row)

      Remove a single row from array
      Parameters:
        `row` - row to be removed

    - #### removeRow

          public void removeRow(int fromRow,
                                int toRow)

      Remove multiple rows from array
      Parameters:
        `fromRow` - first row to be removed (inclusive)
        `toRow` - last row to be removed (inclusive)

    - #### removeColumn

          public void removeColumn(int column)

      Remove a single column from array
      Parameters:
        `column` - column to be removed

    - #### removeColumn

          public void removeColumn(int fromColumn,
                                   int toColumn)

      Remove multiple columns from array
      Parameters:
        `fromColumn` - first column to be removed (inclusive)
        `toColumn` - last column to be removed (inclusive)

    - #### get

          public float get(int x,
                           int y)

      Get a single value from the array
      Parameters:
        `x` - row index
        `y` - column index
      Returns:
        a single value from the array

    - #### getSizeX

          public int getSizeX()

      Getter for number of rows
      Returns:
        number of rows

    - #### getSizeY

          public int getSizeY()

      Getter for the number of columns
      Returns:
        number of columns

    - #### writeObject

          private void writeObject(java.io.ObjectOutputStream out)
                            throws java.io.IOException

      Write object to output stream
      Parameters:
        `out` - object output stream
      Throws:
        `java.io.IOException`

    - #### readObject

          private void readObject(java.io.ObjectInputStream in)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException

      Read object from input stream
      Parameters:
        `in` - object input stream
      Throws:
        `java.io.IOException`
        `java.lang.ClassNotFoundException`

    - #### compressMatrix

          private void compressMatrix()

      Prepare compressed data from full matrix to write out

    - #### expandMatrix

          private void expandMatrix()

      Expand compressed data to full matrix

    - #### deepCopyFrom

          public void deepCopyFrom(CA2DFloat matrix)

      Initialize a compressed matrix by creating a deep copy
      Parameters:
        `matrix` - matrix to be copied from