1 /* $Id: petscbt.h,v 1.21 2001/04/10 19:37:48 bsmith Exp bsmith $ */ 2 3 /* 4 5 BT - Bit array objects: used to compactly store logical arrays of variables. 6 7 PetscBTCreate(m,bt) - creates a bit array with enough room to hold m values 8 PetscBTDestroy(bt) - destroys the bit array 9 PetscBTMemzero(m,bt) - zeros the entire bit array (sets all values to false) 10 PetscBTSet(bt,index) - sets a particular entry as true 11 PetscBTClear(bt,index) - sets a particular entry as false 12 PetscBTLookup(bt,index) - returns the value 13 PetscBTLookupSet(bt,index) - returns the value and then sets it true 14 PetscBTLength(m) - returns number of bytes in array with m bits 15 PetscBTView(m,bt,viewer) - prints all the entries in a bit array 16 17 These routines do not currently have manual pages. 18 19 The are all implemented as macros with the trivial data structure for efficiency. 20 21 These are not thread safe since they use a few global variables. 22 23 We do not currently check error flags on PetscBTSet(), PetscBTClear(), PetscBTLookup(), 24 PetcBTLookupSet(), PetscBTLength() cause error checking would cost hundreds more cycles then 25 the operation. 26 27 */ 28 #if !defined(__PETSCBT_H) 29 #define __PETSCBT_H 30 31 #if !defined(BITSPERBYTE) 32 #define BITSPERBYTE 8 33 #endif 34 35 /*S 36 PetscBT - PETSc bitarrays 37 38 Level: advanced 39 40 Notes: the PetscBT routines do not currently have manual pages. See include/petscbt.h for 41 documentation 42 43 .seealso: PetscBTCreate(), PetscBTDestroy(), PetscBTMemzero(), PetscBTSet(), PetscBTClear(), 44 PetscBTLookup(), PetscBTLookupSet(), PetscBTLength(), PetscBTView() 45 S*/ 46 typedef char* PetscBT; 47 48 extern char _BT_mask,_BT_c; 49 extern int _BT_idx; 50 51 #define PetscBTLength(m) ((m)/BITSPERBYTE+1)*sizeof(char) 52 #define PetscBTMemzero(m,array) PetscMemzero(array,(m)/BITSPERBYTE+1) 53 #define PetscBTDestroy(array) PetscFree(array) 54 55 #define PetscBTView(m,bt,viewer) 0; {\ 56 int __i,_8_ierr; \ 57 PetscViewer __viewer = viewer; \ 58 if (!__viewer) __viewer = PETSC_VIEWER_STDOUT_SELF;\ 59 for (__i=0; __i<m; __i++) { \ 60 _8_ierr = PetscPrintf(((PetscObject)__viewer)->comm,"%d %d\n",__i,PetscBTLookup(bt,__i));CHKERRQ(_8_ierr);\ 61 }} 62 63 #define PetscBTCreate(m,array) 0; { \ 64 int _9_ierr; \ 65 _9_ierr = PetscMalloc(((m)/BITSPERBYTE+1)*sizeof(char),&(array));CHKERRQ(_9_ierr);\ 66 _9_ierr = PetscBTMemzero(m,array);CHKERRQ(_9_ierr);\ 67 } 68 69 #define PetscBTLookupSet(array,index) (_BT_idx = (index)/BITSPERBYTE, \ 70 _BT_c = array[_BT_idx], \ 71 _BT_mask = (char)1 << ((index)%BITSPERBYTE), \ 72 array[_BT_idx] = _BT_c | _BT_mask, \ 73 _BT_c & _BT_mask) 74 75 #define PetscBTSet(array,index) (_BT_idx = (index)/BITSPERBYTE, \ 76 _BT_c = array[_BT_idx], \ 77 _BT_mask = (char)1 << ((index)%BITSPERBYTE), \ 78 array[_BT_idx] = _BT_c | _BT_mask,0) 79 80 81 #define PetscBTClear(array,index) (_BT_idx = (index)/BITSPERBYTE, \ 82 _BT_c = array[_BT_idx], \ 83 _BT_mask = (char)1 << ((index)%BITSPERBYTE), \ 84 array[_BT_idx] = _BT_c & (~_BT_mask),0) 85 86 #define PetscBTLookup(array,index) (_BT_idx = (index)/BITSPERBYTE, \ 87 _BT_c = array[_BT_idx], \ 88 _BT_mask = (char)1 << ((index)%BITSPERBYTE), \ 89 (_BT_c & _BT_mask) != 0) 90 91 #endif 92 93 94