Actual source code: petscbt.h

      6: /*S
      7:      PetscBT - PETSc bitarrays

      9:      Level: advanced

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

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

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

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

     29: S*/
     30: typedef char* PetscBT;

     36: #define PetscBTLength(m)        ((m)/PETSC_BITS_PER_BYTE+1)
     37: #define PetscBTMemzero(m,array) PetscMemzero(array,sizeof(char)*((m)/PETSC_BITS_PER_BYTE+1))
     38: #define PetscBTDestroy(array)   PetscFree(array)

     40: #define PetscBTView(m,bt,viewer) 0; {\
     41:   PetscInt __i; PetscErrorCode _8_ierr; \
     42:   PetscViewer __viewer = viewer; \
     43:   if (!__viewer) __viewer = PETSC_VIEWER_STDOUT_SELF;\
     44:   for (__i=0; __i<m; __i++) { \
     45:     _8_PetscPrintf(((PetscObject)__viewer)->comm,"%D %d\n",__i,PetscBTLookup(bt,__i));CHKERRQ(_8_ierr);\
     46:   }}

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

     51: #define PetscBTLookupSet(array,index) \
     52:   (_BT_idx        = (index)/PETSC_BITS_PER_BYTE, \
     53:    _BT_c          = array[_BT_idx], \
     54:    _BT_mask       = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
     55:    array[_BT_idx] = _BT_c | _BT_mask, \
     56:    _BT_c & _BT_mask)

     58: #define PetscBTSet(array,index)  \
     59:   (_BT_idx        = (index)/PETSC_BITS_PER_BYTE, \
     60:    _BT_c          = array[_BT_idx], \
     61:    _BT_mask       = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
     62:    array[_BT_idx] = _BT_c | _BT_mask,0)

     64: #define PetscBTClear(array,index) \
     65:   (_BT_idx        = (index)/PETSC_BITS_PER_BYTE, \
     66:    _BT_c          = array[_BT_idx], \
     67:    _BT_mask       = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
     68:    array[_BT_idx] = _BT_c & (~_BT_mask),0)

     70: #define PetscBTLookup(array,index) \
     71:   (_BT_idx        = (index)/PETSC_BITS_PER_BYTE, \
     72:    _BT_c          = array[_BT_idx], \
     73:    _BT_mask       = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
     74:    (_BT_c & _BT_mask) != 0)

     77: #endif