danger.util
Class PackedIntVector

java.lang.Object
  extended by danger.util.PackedIntVector


public class PackedIntVector
extends Object

PackedIntVector stores a two-dimensional array of integers in which the number of columns is fixed but the number of rows may be changed on demand. It features a buffer-gap representation so rows in the same vicinity may be added or removed quickly and additional gaps in each column so the values in ranges of rows of the same column may be incremented or decremented quickly.


Constructor Summary
PackedIntVector()
          Create a new PackedIntVector with a single column.
PackedIntVector(int inNumColumns)
          Create a new PackedIntVector with the specified number of columns.
PackedIntVector(int futureRows, int inNumColumns)
          Create a new PackedIntVector with the specified number of columns and space already set aside to add at least the specified number of rows.
 
Method Summary
 void applyColumnDelta(int inColumn, int inValue)
          Increment all values in the specified column by the specified value.
 void applyColumnDelta(int inColumn, int inFirstRow, int inValue)
          Increment all values in the specified column at or below the specified row number by the specified value.
 void applyColumnDelta(int inColumn, int inFirstRow, int inNumRows, int inValue)
          Increment the values in the specified column for the specified number of rows beginning at the specified row by the specified value.
 void ensureCapacity(int inNumNewRows)
          Increase the internal storage of the PackedIntVector to be large enough to hold at least the specified number of rows.
 int newRow()
          Add a row to the bottom of the PackedIntVector, returning the number of the new row.
 int newRow(int[] inValues)
          Add a row to the bottom of the PackedIntVector, returning the number of the new row.
 void newRowAt(int inRow)
          Add a row above (before) the specified row of the PackedIntVector.
 void newRowAt(int inRow, int[] inValues)
          Add a row above (before) the specified row of the PackedIntVector.
 int numColumns()
          Return the number of columns that the PackedIntVector contains.
 int numRows()
          Return the number of rows that the PackedIntVector currently contains.
 void removeAllRows()
          Remove all rows from the PackedIntVector, leaving it with 0 rows.
 void removeRowAt(int inRow)
          Remove the specified row of the PackedIntVector.
 void setValue(int inRow, int[] inValues)
          Set the value in a specified row to a copy of the values in the provided array, which must be at least as large as the number of columns in the PackedIntVector, or null, in which case it will be treated as all zeroes.
 void setValue(int inRow, int inColumn, int inValue)
          Set the value of a specified row and column to the specified value.
 int[] valueAt(int inRow)
          Return a new array of integers containing a copy of the values in the specified row.
 int valueAt(int inRow, int inColumn)
          Return the value at the specified row and column.
 int[] valueAt(int inRow, int[] ioStorage)
          Fill in the specified array of integers, which must be at least as large as the number of the columns in the PackedIntVector, with a copy of the specified row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackedIntVector

public PackedIntVector()
Create a new PackedIntVector with a single column.


PackedIntVector

public PackedIntVector(int inNumColumns)
Create a new PackedIntVector with the specified number of columns.


PackedIntVector

public PackedIntVector(int futureRows,
                       int inNumColumns)
Create a new PackedIntVector with the specified number of columns and space already set aside to add at least the specified number of rows. The initial number of rows is always 0 at creation no matter what argument is provided.

Method Detail

valueAt

public int valueAt(int inRow,
                   int inColumn)
Return the value at the specified row and column.


valueAt

public int[] valueAt(int inRow)
Return a new array of integers containing a copy of the values in the specified row.


valueAt

public int[] valueAt(int inRow,
                     int[] ioStorage)
Fill in the specified array of integers, which must be at least as large as the number of the columns in the PackedIntVector, with a copy of the specified row.


ensureCapacity

public final void ensureCapacity(int inNumNewRows)
Increase the internal storage of the PackedIntVector to be large enough to hold at least the specified number of rows. There is no reason to call this unless you know in advance exactly how many rows you will be adding, in which case it may be slightly faster to preallocate the space.


newRow

public final int newRow()
Add a row to the bottom of the PackedIntVector, returning the number of the new row. All columns of the row will be set to 0.


newRow

public final int newRow(int[] inValues)
Add a row to the bottom of the PackedIntVector, returning the number of the new row. The array provided must be at least as large as the number of columns in the PackedIntVector and that many entries will be copied into the new row.


newRowAt

public final void newRowAt(int inRow)
Add a row above (before) the specified row of the PackedIntVector. All columns of the row will be set to 0.


newRowAt

public final void newRowAt(int inRow,
                           int[] inValues)
Add a row above (before) the specified row of the PackedIntVector. The array provided must be at least as large as the number of columns in the PackedIntVector and that many entries will be copied into the new row, or null, in which case the row will be populated with zeroes.


removeRowAt

public final void removeRowAt(int inRow)
Remove the specified row of the PackedIntVector.


setValue

public final void setValue(int inRow,
                           int inColumn,
                           int inValue)
Set the value of a specified row and column to the specified value. The row and column must be within the range of currently existing rows and columns.


setValue

public final void setValue(int inRow,
                           int[] inValues)
Set the value in a specified row to a copy of the values in the provided array, which must be at least as large as the number of columns in the PackedIntVector, or null, in which case it will be treated as all zeroes. The row must be within the range of currently existing rows.


applyColumnDelta

public final void applyColumnDelta(int inColumn,
                                   int inValue)
Increment all values in the specified column by the specified value.


applyColumnDelta

public final void applyColumnDelta(int inColumn,
                                   int inFirstRow,
                                   int inValue)
Increment all values in the specified column at or below the specified row number by the specified value.


applyColumnDelta

public final void applyColumnDelta(int inColumn,
                                   int inFirstRow,
                                   int inNumRows,
                                   int inValue)
Increment the values in the specified column for the specified number of rows beginning at the specified row by the specified value.


removeAllRows

public final void removeAllRows()
Remove all rows from the PackedIntVector, leaving it with 0 rows.


numColumns

public final int numColumns()
Return the number of columns that the PackedIntVector contains.


numRows

public final int numRows()
Return the number of rows that the PackedIntVector currently contains.