org.knowceans.util
Class ArrayCache<T>

java.lang.Object
  extended by org.knowceans.util.ArrayCache<T>
Type Parameters:
T - type of the array elements

public class ArrayCache<T>
extends java.lang.Object

ArrayCache represents a cache for a large multidimensional array, with the minor dimensions being type-dependent. The outmost array, say int[][] is completely exposed to programming code, allowing the developer usage of the ordinary array data structure. If code is about to access other parts of the array, a fetch() message is sent to the array. After it is clear that the element will not be touched for a while, a done() message is sent.

The idea is to lookup a row in the main array and check whether this is loaded. All rows not currently fetched are set to null. The user needs to either fetch the data to work on a given row or put it into the array themselves and call done() on the row.

Author:
gregor

Constructor Summary
ArrayCache(java.lang.String backend, int rowsize, int typesize, T[] array)
          init the cache with the backend file and array
ArrayCache(java.lang.String backend, T[] array, int rowsize, int typesize, java.lang.String access)
          init the cache with the backend file and array
 
Method Summary
 boolean done(int row)
          done with the single row
 boolean done(int rowstart, int length)
           
 boolean fetch(int row)
          fetch a single row
 boolean fetch(int rowstart, int length)
          fetch a range of the array from the backend
static void main(java.lang.String[] args)
           
 boolean save()
          save the complete array to the backend
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayCache

public ArrayCache(java.lang.String backend,
                  int rowsize,
                  int typesize,
                  T[] array)
           throws java.io.FileNotFoundException
init the cache with the backend file and array

Parameters:
backend -
array - the T[length] array with all higher dimensions null or filled
rowsize - length of rows
typesize - size of one row element in bytes (array length x element size for multidimensional arrays)
Throws:
java.io.FileNotFoundException

ArrayCache

public ArrayCache(java.lang.String backend,
                  T[] array,
                  int rowsize,
                  int typesize,
                  java.lang.String access)
           throws java.io.FileNotFoundException
init the cache with the backend file and array

Parameters:
backend -
array - the T[length] array with all higher dimensions null or filled
rowsize - length of rows
typesize - size of one row element in bytes (array length x element size for multidimensional arrays)
access - string to control behaviour of file backend: r(ead)|w(rite)|s(ynced)
Throws:
java.io.FileNotFoundException
Method Detail

main

public static void main(java.lang.String[] args)

fetch

public boolean fetch(int rowstart,
                     int length)
              throws java.io.IOException
fetch a range of the array from the backend

Parameters:
rowstart -
length -
Returns:
Throws:
java.io.IOException

fetch

public boolean fetch(int row)
fetch a single row

Parameters:
row -
Returns:

done

public boolean done(int rowstart,
                    int length)
Parameters:
rowstart -
length -
Returns:

done

public boolean done(int row)
done with the single row

Parameters:
row -
Returns:

save

public boolean save()
save the complete array to the backend

Returns: