Actual source code: petscbt.h
5: /*S
6: PetscBT - PETSc bitarrays
8: Level: advanced
10: PetscBTCreate(m,bt) - creates a bit array with enough room to hold m values
11: PetscBTDestroy(bt) - destroys the bit array
12: PetscBTMemzero(m,bt) - zeros the entire bit array (sets all values to false)
13: PetscBTSet(bt,index) - sets a particular entry as true
14: PetscBTClear(bt,index) - sets a particular entry as false
15: PetscBTLookup(bt,index) - returns the value
16: PetscBTLookupSet(bt,index) - returns the value and then sets it true
17: PetscBTLength(m) - returns number of bytes in array with m bits
18: PetscBTView(m,bt,viewer) - prints all the entries in a bit array
20: The are all implemented as macros with the trivial data structure for efficiency.
22: These are not thread safe since they use a few global variables.
24: We do not currently check error flags on PetscBTSet(), PetscBTClear(), PetscBTLookup(),
25: PetcBTLookupSet(), PetscBTLength() cause error checking would cost hundreds more cycles then
26: the operation.
28: S*/
29: typedef char* PetscBT;
35: #define PetscBTLength(m) ((m)/PETSC_BITS_PER_BYTE+1)
36: #define PetscBTMemzero(m,array) PetscMemzero(array,sizeof(char)*((m)/PETSC_BITS_PER_BYTE+1))
37: #define PetscBTDestroy(array) PetscFree(array)
39: #define PetscBTView(m,bt,viewer) 0; {\
40: PetscInt __i; PetscErrorCode _8_ierr; \
41: PetscViewer __viewer = viewer; \
42: if (!__viewer) __viewer = PETSC_VIEWER_STDOUT_SELF;\
43: for (__i=0; __i<m; __i++) { \
44: _8_PetscPrintf(((PetscObject)__viewer)->comm,"%D %d\n",__i,PetscBTLookup(bt,__i));CHKERRQ(_8_ierr);\
45: }}
47: #define PetscBTCreate(m,array) \
48: (PetscMalloc(((m)/PETSC_BITS_PER_BYTE+1)*sizeof(char),&(array)) || PetscBTMemzero(m,array))
50: #define PetscBTLookupSet(array,index) \
51: (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \
52: _BT_c = array[_BT_idx], \
53: _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
54: array[_BT_idx] = _BT_c | _BT_mask, \
55: _BT_c & _BT_mask)
57: #define PetscBTSet(array,index) \
58: (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \
59: _BT_c = array[_BT_idx], \
60: _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
61: array[_BT_idx] = _BT_c | _BT_mask,0)
63: #define PetscBTClear(array,index) \
64: (_BT_idx = (index)/PETSC_BITS_PER_BYTE, \
65: _BT_c = array[_BT_idx], \
66: _BT_mask = (char)1 << ((index)%PETSC_BITS_PER_BYTE), \
67: array[_BT_idx] = _BT_c & (~_BT_mask),0)
69: #define PetscBTLookup(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: (_BT_c & _BT_mask) != 0)
76: #endif