Actual source code: petscbt.h

  1: /* $Id: petscbt.h,v 1.22 2001/09/07 20:13:16 bsmith Exp $ */

  3: /*    

  5:           BT - Bit array objects: used to compactly store logical arrays of variables.

  7:      PetscBTCreate(m,bt)        - creates a bit array with enough room to hold m values
  8:      PetscBTDestroy(bt)         - destroys the bit array
  9:      PetscBTMemzero(m,bt)       - zeros the entire bit array (sets all values to false)
 10:      PetscBTSet(bt,index)       - sets a particular entry as true
 11:      PetscBTClear(bt,index)     - sets a particular entry as false
 12:      PetscBTLookup(bt,index)    - returns the value 
 13:      PetscBTLookupSet(bt,index) - returns the value and then sets it true
 14:      PetscBTLength(m)           - returns number of bytes in array with m bits
 15:      PetscBTView(m,bt,viewer)   - prints all the entries in a bit array

 17:     These routines do not currently have manual pages.

 19:     The are all implemented as macros with the trivial data structure for efficiency.

 21:     These are not thread safe since they use a few global variables.

 23:     We do not currently check error flags on PetscBTSet(), PetscBTClear(), PetscBTLookup(),
 24:     PetcBTLookupSet(), PetscBTLength() cause error checking would cost hundreds more cycles then
 25:     the operation.

 27: */
 30: PETSC_EXTERN_CXX_BEGIN

 32: /*S
 33:      PetscBT - PETSc bitarrays

 35:    Level: advanced

 37:    Notes: the PetscBT routines do not currently have manual pages. See include/petscbt.h for 
 38:           documentation

 40: .seealso:  PetscBTCreate(), PetscBTDestroy(), PetscBTMemzero(), PetscBTSet(), PetscBTClear(),
 41:            PetscBTLookup(), PetscBTLookupSet(), PetscBTLength(), PetscBTView()
 42: S*/
 43: #define PetscBT char*

 45: extern char _BT_mask,_BT_c;
 46: extern int  _BT_idx;

 48: #define PetscBTLength(m)        ((m)/PETSC_BITS_PER_BYTE+1)*sizeof(char)
 49: #define PetscBTMemzero(m,array) PetscMemzero(array,(m)/PETSC_BITS_PER_BYTE+1)
 50: #define PetscBTDestroy(array)   PetscFree(array)

 52: #define PetscBTView(m,bt,viewer) 0; {\
 53:   int    __i,_8_ierr; \
 54:   PetscViewer __viewer = viewer; \
 55:   if (!__viewer) __viewer = PETSC_VIEWER_STDOUT_SELF;\
 56:   for (__i=0; __i<m; __i++) { \
 57:     _8_PetscPrintf(((PetscObject)__viewer)->comm,"%d %d\n",__i,PetscBTLookup(bt,__i));CHKERRQ(_8_ierr);\
 58:   }}

 60: #define PetscBTCreate(m,array)  \
 61:   (PetscMalloc(((m)/PETSC_BITS_PER_BYTE+1)*sizeof(char),&(array)) || PetscBTMemzero(m,array))

 63: #define PetscBTLookupSet(array,index)   (_BT_idx           = (index)/PETSC_BITS_PER_BYTE, \
 64:                                         _BT_c           = array[_BT_idx], \
 65:                                         _BT_mask        = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
 66:                                         array[_BT_idx]  = _BT_c | _BT_mask, \
 67:                                         _BT_c & _BT_mask)

 69: #define PetscBTSet(array,index)         (_BT_idx          = (index)/PETSC_BITS_PER_BYTE, \
 70:                                         _BT_c           = array[_BT_idx], \
 71:                                         _BT_mask        = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
 72:                                         array[_BT_idx]  = _BT_c | _BT_mask,0)


 75: #define PetscBTClear(array,index)  (_BT_idx          = (index)/PETSC_BITS_PER_BYTE, \
 76:                                    _BT_c           = array[_BT_idx], \
 77:                                    _BT_mask        = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
 78:                                    array[_BT_idx]  = _BT_c & (~_BT_mask),0)

 80: #define PetscBTLookup(array,index) (_BT_idx          = (index)/PETSC_BITS_PER_BYTE, \
 81:                                    _BT_c           = array[_BT_idx], \
 82:                                    _BT_mask        = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
 83:                                    (_BT_c & _BT_mask) != 0)

 85: PETSC_EXTERN_CXX_END
 86: #endif