Actual source code: petscbt.h

  1: /*    

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

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

 15:     These routines do not currently have manual pages.

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

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

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

 25: */

 30: /*S
 31:      PetscBT - PETSc bitarrays

 33:    Level: advanced

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

 38: .seealso:  PetscBTCreate(), PetscBTDestroy(), PetscBTMemzero(), PetscBTSet(), PetscBTClear(),
 39:            PetscBTLookup(), PetscBTLookupSet(), PetscBTLength(), PetscBTView()
 40: S*/
 41: typedef char* PetscBT;


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

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

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

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

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


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

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

 84: #endif