Actual source code: petscbt.h

      1: #pragma once

      3: #include <petscsystypes.h>
      4: #include <petscviewertypes.h>
      5: #include <petscstring.h>

      7: /* SUBMANSEC = Sys */

      9: /* convert an index i to an index suitable for indexing a PetscBT, such that
     10:  * bt[PetscBTIndex(i)] returns the i'th value of the bt */
     11: static inline size_t PetscBTIndex_Internal(PetscInt index)
     12: {
     13:   return (size_t)index / PETSC_BITS_PER_BYTE;
     14: }

     16: static inline char PetscBTMask_Internal(PetscInt index)
     17: {
     18:   return (char)(1 << index % PETSC_BITS_PER_BYTE);
     19: }

     21: static inline size_t PetscBTLength(PetscInt m)
     22: {
     23:   return (size_t)m / PETSC_BITS_PER_BYTE + 1;
     24: }

     26: static inline PetscErrorCode PetscBTMemzero(PetscInt m, PetscBT array)
     27: {
     28:   return PetscArrayzero(array, PetscBTLength(m));
     29: }

     31: static inline PetscErrorCode PetscBTDestroy(PetscBT *array)
     32: {
     33:   return (*array) ? PetscFree(*array) : PETSC_SUCCESS;
     34: }

     36: static inline PetscErrorCode PetscBTCreate(PetscInt m, PetscBT *array)
     37: {
     38:   return PetscCalloc1(PetscBTLength(m), array);
     39: }

     41: static inline char PetscBTLookup(PetscBT array, PetscInt index)
     42: {
     43:   return array[PetscBTIndex_Internal(index)] & PetscBTMask_Internal(index);
     44: }

     46: static inline PetscErrorCode PetscBTSet(PetscBT array, PetscInt index)
     47: {
     48:   PetscFunctionBegin;
     49:   array[PetscBTIndex_Internal(index)] |= PetscBTMask_Internal(index);
     50:   PetscFunctionReturn(PETSC_SUCCESS);
     51: }

     53: static inline PetscErrorCode PetscBTNegate(PetscBT array, PetscInt index)
     54: {
     55:   PetscFunctionBegin;
     56:   array[PetscBTIndex_Internal(index)] ^= PetscBTMask_Internal(index);
     57:   PetscFunctionReturn(PETSC_SUCCESS);
     58: }

     60: static inline PetscErrorCode PetscBTClear(PetscBT array, PetscInt index)
     61: {
     62:   PetscFunctionBegin;
     63:   array[PetscBTIndex_Internal(index)] &= (char)~PetscBTMask_Internal(index);
     64:   PetscFunctionReturn(PETSC_SUCCESS);
     65: }

     67: static inline char PetscBTLookupSet(PetscBT array, PetscInt index)
     68: {
     69:   const char ret = PetscBTLookup(array, index);
     70:   PetscCallContinue(PetscBTSet(array, index));
     71:   return ret;
     72: }

     74: static inline char PetscBTLookupClear(PetscBT array, PetscInt index)
     75: {
     76:   const char ret = PetscBTLookup(array, index);
     77:   PetscCallContinue(PetscBTClear(array, index));
     78:   return ret;
     79: }

     81: PETSC_EXTERN PetscErrorCode PetscBTView(PetscInt, const PetscBT, PetscViewer);