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;

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

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

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

     62: #define PetscBTLookupSet(array,index) \
     63:   (_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)  \
     70:   (_BT_idx        = (index)/PETSC_BITS_PER_BYTE, \
     71:    _BT_c          = array[_BT_idx], \
     72:    _BT_mask       = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
     73:    array[_BT_idx] = _BT_c | _BT_mask,0)

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

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

     88: #endif