edu.unh.sdb.datasource
Class DSBlockStencil

java.lang.Object
  extended by edu.unh.sdb.datasource.DSStencil
      extended by edu.unh.sdb.datasource.DSPartitionedStencil
          extended by edu.unh.sdb.datasource.DSBlockStencil

public class DSBlockStencil
extends DSPartitionedStencil

This is an implementation of a partitioned stencil that associates a Datablock with active elements. It uses an array to maintain the record of active elements. As a result, the set and get methods are extremely fast, but iteration might be a little less efficient than the list implementation. However, it does not tax the garbage collector, so it may be more appropriate for repeated use.


Field Summary
protected  int dataBytesUsed
           
protected  DataBlock[] inStencil
           
protected  int lastActiveOffset
           
protected  int lastIndexRequested
           
protected  RecordDescriptor recordDescriptor
           
protected  int size
           
 
Fields inherited from class edu.unh.sdb.datasource.DSPartitionedStencil
headerLength, partitioning, partitioningDimensionsArray, partitionListBytesLength
 
Fields inherited from class edu.unh.sdb.datasource.DSStencil
dimensionality, space
 
Constructor Summary
DSBlockStencil(RegularISPartitioning partitioning, RecordDescriptor recordDescriptor)
          Construct a stencil that identifies areas of interest using a partitioning.
 
Method Summary
 void clear()
          Clear this stencil of all elements.
 boolean get(IndexSpaceID id)
          Return true if the given id maps to an active stencil element, false otherwise.
 byte[] getData(byte[] data)
          Fill the given byte array with the data contained in the active elements of this stencil.
 DataBlock getDataBlock(IndexSpaceID id)
          Return true if the given id maps to an active stencil element, false otherwise.
 int getDataBytesUsed()
          Return the number of bytes actually used in the last call to getData().
 DataBlock getIndexedBlock(int index)
          Return the DataBlock corresponding to the specified stencil element.
 DataBlock getIndexedBlockAndBounds(ISBounds stencilBounds, int index)
          Return the DataBlock corresponding to the specified stencil element.
 ISBounds getIndexedBounds(ISBounds stencilBounds, int index)
          Sets the argument ISBounds to the bounds of the specified stencil element.
protected  long getIndexedOffset(int index)
          Return the partition offset corresponding to the given index.
 int getStorageType()
           
static void main(java.lang.String[] argv)
           
 boolean set(IndexSpaceID id)
          Set the stencil element containing the id to "active".
 boolean set(IndexSpaceID id, DataBlock block)
          Set the stencil element containing the id to "active", associating the given DataBlock with that element.
 void setData(byte[] data)
          Populate the active elements (Datablocks) of this stencil with the data found in the given array.
 boolean setElement(IndexSpaceID pid)
          Set the stencil element with index corresponding to id to "active.
 boolean setElement(IndexSpaceID pid, DataBlock block)
          Set the stencil element with index corresponding to id to "active", associating the given DataBlock with that element.
protected  void setElementFromOffset(int offset)
          Set the element corresponding to the 1D offset to be active.
 void setShortData(byte[] data)
          Populate the active elements (Datablocks) of this stencil with the data found in the given array.
 int size()
          return number of active elements contained by this stencil
 java.lang.String toString()
          Return a String representing the object.
 java.lang.String toString(java.lang.String indent)
           
 
Methods inherited from class edu.unh.sdb.datasource.DSPartitionedStencil
chooseBytesPerValue, getPartitionDimensions, getPartitionDimensionsArray, getPartitioningDimensions, getPartitionListBytes, getPartitionListBytesLength, inPartitioningBounds, inPartitioningBounds, partitionVolume, setPartitionListFromBytes, volume
 
Methods inherited from class edu.unh.sdb.datasource.DSStencil
dim, getIndexedBounds, getSpaceBounds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inStencil

protected DataBlock[] inStencil

recordDescriptor

protected RecordDescriptor recordDescriptor

size

protected int size

lastIndexRequested

protected int lastIndexRequested

lastActiveOffset

protected int lastActiveOffset

dataBytesUsed

protected int dataBytesUsed
Constructor Detail

DSBlockStencil

public DSBlockStencil(RegularISPartitioning partitioning,
                      RecordDescriptor recordDescriptor)
Construct a stencil that identifies areas of interest using a partitioning. The first argument is the dimensions of an element of the partitioning, meaning that the index space bounded by the second argument will be divided up into pieces of the shape described by the first argument. For example, if we build an 8x8 partitioning of a 128x128 index space, each element of the partitioning will have dimensions 16x16. In this situation, the first argument for this constructor should be [16,16] and the second argument should be {<0,0>, <127,127>}.

Method Detail

getData

public byte[] getData(byte[] data)
Fill the given byte array with the data contained in the active elements of this stencil. If the given array is not long enough to contain the stencil data, a new array is allocated and returned. The number of bytes actually used in the array can be retrieved by calling getDataBytesUsed().


getDataBytesUsed

public int getDataBytesUsed()
Return the number of bytes actually used in the last call to getData().


setData

public void setData(byte[] data)
Populate the active elements (Datablocks) of this stencil with the data found in the given array. This method assumes that the array data was generated by the getData() method of a stencil exactly equivalent to this one. In particular, the stencil dimensions must all be identical, and the same elements must already be active.


setShortData

public void setShortData(byte[] data)
Populate the active elements (Datablocks) of this stencil with the data found in the given array. This method assumes that the array data was generated by the getData() method of a stencil exactly equivalent to this one. In particular, the stencil dimensions must all be identical, and the same elements must already be active.


getStorageType

public int getStorageType()

set

public boolean set(IndexSpaceID id)
Set the stencil element containing the id to "active". If it is already active, then the method returns false. Returns true otherwise. Not implemented.

Specified by:
set in class DSStencil

setElement

public boolean setElement(IndexSpaceID pid)
Set the stencil element with index corresponding to id to "active. id should already have been mapped to the partitioning space. If it is already active, then the method returns false. Returns true otherwise. Not implemented.

Specified by:
setElement in class DSStencil

set

public boolean set(IndexSpaceID id,
                   DataBlock block)
Set the stencil element containing the id to "active", associating the given DataBlock with that element. If it is already active, then the method does not associate the new DataBlock with the element, and returns false. Returns true otherwise.


setElement

public boolean setElement(IndexSpaceID pid,
                          DataBlock block)
Set the stencil element with index corresponding to id to "active", associating the given DataBlock with that element. id should already have been mapped to the partitioning space. If the element is already active, then the new DataBlock is not associated, and the method returns false. Returns true otherwise.


get

public boolean get(IndexSpaceID id)
Return true if the given id maps to an active stencil element, false otherwise.

Specified by:
get in class DSStencil

getDataBlock

public DataBlock getDataBlock(IndexSpaceID id)
Return true if the given id maps to an active stencil element, false otherwise.


getIndexedBounds

public ISBounds getIndexedBounds(ISBounds stencilBounds,
                                 int index)
Sets the argument ISBounds to the bounds of the specified stencil element. The ordering of the stencil elements is arbitrary. If the specified index is not less than the number of elements, then the bounds argument is not changed, and the method returns null. Otherwise, the bounds are modified and a reference to the argument bounds is returned.

Specified by:
getIndexedBounds in class DSStencil

getIndexedBlock

public DataBlock getIndexedBlock(int index)
Return the DataBlock corresponding to the specified stencil element. The ordering of the stencil elements is arbitrary. If the specified index is not less than the number of elements, then the method returns null.


getIndexedBlockAndBounds

public DataBlock getIndexedBlockAndBounds(ISBounds stencilBounds,
                                          int index)
Return the DataBlock corresponding to the specified stencil element. The ordering of the stencil elements is arbitrary. If the specified index is not less than the number of elements, then the method returns null. The ISBounds argument will be set to the bounds in the stencil space corresponding to this DataBlock.


getIndexedOffset

protected final long getIndexedOffset(int index)
Return the partition offset corresponding to the given index.

Specified by:
getIndexedOffset in class DSPartitionedStencil

setElementFromOffset

protected void setElementFromOffset(int offset)
Set the element corresponding to the 1D offset to be active. Not implemented.

Specified by:
setElementFromOffset in class DSPartitionedStencil

size

public int size()
return number of active elements contained by this stencil

Specified by:
size in class DSStencil

clear

public void clear()
Clear this stencil of all elements.

Specified by:
clear in class DSPartitionedStencil

toString

public java.lang.String toString()
Return a String representing the object.

Overrides:
toString in class DSPartitionedStencil

toString

public java.lang.String toString(java.lang.String indent)
Overrides:
toString in class DSPartitionedStencil

main

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