FreePOOMA  2.4.1
Classes | Public Types | Public Member Functions | Static Public Member Functions
CompressibleBlock< T > Class Template Reference

CompressibleBlock (CBlock) provides the storage for Pooma's compressible brick engine. More...

#include <CompressibleBlock.h>

List of all members.

Classes

class  CompressibleBlockController

Public Types

enum  Notifier { notifyDestruct = 0, notifyUncompress = 1, notifyCompress = 2 }
typedef CompressibleBlock< T > This_t
typedef T Element_t
typedef Pooma::DataObject_t DataObject_t

Public Member Functions

 CompressibleBlock ()
 CompressibleBlock (int size)
 CompressibleBlock (int size, int affinity)
 CompressibleBlock (int size, int affinity, const T &model)
 CompressibleBlock (const CompressibleBlock &block)
 ~CompressibleBlock ()
int size () const
int capacity () const
bool resize (int newsize, const typename DataBlockPtr< T >::NoInitTag &)
void setSize (int newsize)
DataObject_tdataObject () const
int affinity () const
bool compressed () const
T * data ()
void uncompress () const
void tryCompress ()
DataBlockPtr< T > view () const
DataBlockPtr< T > dataBlock () const
void makeOwnCopy ()
void invalidate ()
bool isControllerPtrValid () const
bool isControllerValid () const
bool isControllerValidUnlocked () const
bool isShared () const
bool operator!= (const This_t &a) const
bool operator== (const This_t &a) const
void attach (Observer< T * > *o)
void detach (Observer< T * > *o)
void lock () const
void unlock () const

Static Public Member Functions

static int randomTries ()

Detailed Description

template<class T>
class CompressibleBlock< T >

CompressibleBlock (CBlock) provides the storage for Pooma's compressible brick engine.

Compressible brick engines need a data storage class that manages a block of data that has the following characteristics:

  1. It manages a block of data of some size.
  2. If all of the data in the block has the same value, then a single value can be stored. This is the "compressed" state.
  3. It must provide access to the uncompressed data; i.e. it is sometimes necessary to take an "uncompressed view".
  4. While uncompressed views exist, the data must remain "incompressible". Once the last uncompressed view is destroyed, the block should attempt to compress itself.
  5. When the block compresses or uncompresses, it must notify users (compressible bricks and brickviews) so that they can sync their internal state with that of the block.
  6. This all needs to be thread safe. Compression/decompression usually occur when iterates are run or destroyed, so much of this happens asynchronously.
  7. Whether the block is compressed or uncompressed, it must appear to be the same logical object. In particular, it must maintain the same identity as viewed by the runtime system.
  8. It needs to have shallow copy semantics.
  9. If Pooma::neverCompress() returns true, then everything should always be in the uncompressed state.

Since there can be multiple views (shallow copies) of the compressible block (both of the data and the data-object), it is important that the state be maintained by a separate object. Thus, CompressibleBlock is simply an envelope that holds a ref-counted pointer to a Compressible- BlockController (CBC). The CBC is a private nested class and thus does not appear directly in the user interface. However it is an important element of the design. CBlock itself is just an envelope that passes messages on to the CBC.

Given all that, here is how views of the data work: There can be compressible brick views (CompBrick and CompBrickViews) of the data. These all share the same CBlock, and they do not care whether the CBlock is compressed or not. There can also be plain BrickViews of the uncompressed data. When the last BrickView is destroyed, the CBlock should try to compress itself. Here is a diagram, then, of the possible views:

  BrickView---->DataBlockPtr<-----CBlock<-----CompBrick
    BrickView------^               ^----CompBrickView
 

In order for CompBrick and CBlock to have consistent compressibility state, we must use the observer pattern and make it thread safe. Thus we have the following relationships amongst the classes:

CBC observes the DataBlockPtr (~DataBlockPtr calls notify)

CompBrick/CompBrickView observes the CBlock (the CBC really as attach/detach simply pass the request on) (CBC::trycompress and CBC::uncompress call notify)


Member Typedef Documentation

template<class T >
typedef CompressibleBlock<T> CompressibleBlock< T >::This_t
template<class T >
typedef T CompressibleBlock< T >::Element_t
template<class T >
typedef Pooma::DataObject_t CompressibleBlock< T >::DataObject_t

Member Enumeration Documentation

template<class T >
enum CompressibleBlock::Notifier
Enumerator:
notifyDestruct 
notifyUncompress 
notifyCompress 

Constructor & Destructor Documentation

template<class T >
CompressibleBlock< T >::CompressibleBlock ( ) [inline]
template<class T >
CompressibleBlock< T >::CompressibleBlock ( int  size) [inline, explicit]
template<class T >
CompressibleBlock< T >::CompressibleBlock ( int  size,
int  affinity 
) [inline]
template<class T >
CompressibleBlock< T >::CompressibleBlock ( int  size,
int  affinity,
const T &  model 
) [inline]
template<class T >
CompressibleBlock< T >::CompressibleBlock ( const CompressibleBlock< T > &  block) [inline]
template<class T >
CompressibleBlock< T >::~CompressibleBlock ( ) [inline]

Member Function Documentation

template<class T >
int CompressibleBlock< T >::size ( ) const [inline]
template<class T >
int CompressibleBlock< T >::capacity ( ) const [inline]
template<class T >
bool CompressibleBlock< T >::resize ( int  newsize,
const typename DataBlockPtr< T >::NoInitTag &   
) [inline]
template<class T >
void CompressibleBlock< T >::setSize ( int  newsize) [inline]
template<class T >
DataObject_t* CompressibleBlock< T >::dataObject ( ) const [inline]
template<class T >
int CompressibleBlock< T >::affinity ( ) const [inline]
template<class T >
bool CompressibleBlock< T >::compressed ( ) const [inline]
template<class T >
T* CompressibleBlock< T >::data ( ) [inline]
template<class T >
void CompressibleBlock< T >::uncompress ( ) const [inline]
template<class T >
void CompressibleBlock< T >::tryCompress ( ) [inline]
template<class T >
DataBlockPtr<T> CompressibleBlock< T >::view ( ) const [inline]
template<class T >
DataBlockPtr<T> CompressibleBlock< T >::dataBlock ( ) const [inline]
template<class T >
void CompressibleBlock< T >::makeOwnCopy ( ) [inline]
template<class T >
void CompressibleBlock< T >::invalidate ( ) [inline]
template<class T >
bool CompressibleBlock< T >::isControllerPtrValid ( ) const [inline]
template<class T >
bool CompressibleBlock< T >::isControllerValid ( ) const [inline]
template<class T >
bool CompressibleBlock< T >::isControllerValidUnlocked ( ) const [inline]
template<class T >
bool CompressibleBlock< T >::isShared ( ) const [inline]
template<class T >
bool CompressibleBlock< T >::operator!= ( const This_t a) const [inline]
template<class T >
bool CompressibleBlock< T >::operator== ( const This_t a) const [inline]
template<class T >
void CompressibleBlock< T >::attach ( Observer< T * > *  o) [inline]
template<class T >
void CompressibleBlock< T >::detach ( Observer< T * > *  o) [inline]
template<class T >
void CompressibleBlock< T >::lock ( ) const [inline]
template<class T >
void CompressibleBlock< T >::unlock ( ) const [inline]
template<class T >
static int CompressibleBlock< T >::randomTries ( ) [inline, static]

The documentation for this class was generated from the following file: