iitb.con.util
Class IntArrayGrid

java.lang.Object
  extended by iitb.con.util.IntArrayGrid

public class IntArrayGrid
extends java.lang.Object

IntArrayGrid is a unbound grid structure for integer values. The number of columns in the grid is fixed at creation time, while the rows are unbound. ArrayGrid is limited with the size of 4KB (by default), since it is useful to store in the disk.


Field Summary
static int BLOCK_SIZE
          Size of the BLOCK
 int id
          Id for the array grid
 int length
          Number of entries present in the grid
 
Constructor Summary
IntArrayGrid(int id, int cols)
          Initializes with id and number of columns
IntArrayGrid(int id, int cols, java.nio.ByteBuffer buf)
          Initializes with id and number of columns and the byte buffer is used to initial the values in the grid; will be useful if user is reading the data from the disk and constructing the array grid
 
Method Summary
 int add(int... values)
          Adds the values for a row to the grid
 void dump()
          Prints the contents of array grid
 int[] getCol(int index)
          Returns the column for the specified index
 int[] getRowByBinarySearch(int key)
          Returns the row as integer array based on the given key match with first column.
Returns first match in case of duplicate keys.
 int[][] getRows(int key, int col)
          Returns the rows as 2d integer array based on the given key match with the specified column.
 boolean setRow(int key, int matchCol, int... values)
          Sets the row value based on the matching value in the grid
 void sort()
          Sorts the grid based on the first column value
 java.nio.ByteBuffer toBuffer()
          Returns the array grid contents as bytes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLOCK_SIZE

public static final int BLOCK_SIZE
Size of the BLOCK

See Also:
Constant Field Values

id

public int id
Id for the array grid


length

public int length
Number of entries present in the grid

Constructor Detail

IntArrayGrid

public IntArrayGrid(int id,
                    int cols)
Initializes with id and number of columns

Parameters:
id - id for the array grid; will be useful if a program uses multiple grids
cols - number of columns

IntArrayGrid

public IntArrayGrid(int id,
                    int cols,
                    java.nio.ByteBuffer buf)
Initializes with id and number of columns and the byte buffer is used to initial the values in the grid; will be useful if user is reading the data from the disk and constructing the array grid

Parameters:
id - id for the array grid; will be useful if a program uses multiple grids
cols - number of columns
buf - array grid's bytebuffer
Method Detail

add

public int add(int... values)
Adds the values for a row to the grid

Parameters:
values - variable number of values based on the column size
Returns:
row location on success, else return -1

dump

public void dump()
Prints the contents of array grid


getCol

public int[] getCol(int index)
Returns the column for the specified index

Parameters:
index - column index
Returns:
column as integer array

getRowByBinarySearch

public int[] getRowByBinarySearch(int key)
Returns the row as integer array based on the given key match with first column.
Returns first match in case of duplicate keys.

Parameters:
key - key value to be searched
Returns:
the row as integer array on match, else NULL

getRows

public int[][] getRows(int key,
                       int col)
Returns the rows as 2d integer array based on the given key match with the specified column.

Parameters:
key - key value to be searched
col - the column to be searched
Returns:
the row as 2d integer array on match, else NULL

setRow

public boolean setRow(int key,
                      int matchCol,
                      int... values)
Sets the row value based on the matching value in the grid

Parameters:
key - key to be matched
matchCol - column used for matching
values - values to be set
Returns:
true on success

sort

public void sort()
Sorts the grid based on the first column value


toBuffer

public java.nio.ByteBuffer toBuffer()
Returns the array grid contents as bytes

Returns:
array grid contents as ByteBuffer