Actual source code: petscbt.h
1: /* $Id: petscbt.h,v 1.21 2001/04/10 19:37:48 bsmith Exp $ */
3: /*
5: BT - Bit array objects: used to compactly store logical arrays of variables.
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
17: These routines do not currently have manual pages.
19: The are all implemented as macros with the trivial data structure for efficiency.
21: These are not thread safe since they use a few global variables.
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.
27: */
31: #if !defined(BITSPERBYTE)
32: #define BITSPERBYTE 8
33: #endif
35: /*S
36: PetscBT - PETSc bitarrays
38: Level: advanced
40: Notes: the PetscBT routines do not currently have manual pages. See include/petscbt.h for
41: documentation
43: .seealso: PetscBTCreate(), PetscBTDestroy(), PetscBTMemzero(), PetscBTSet(), PetscBTClear(),
44: PetscBTLookup(), PetscBTLookupSet(), PetscBTLength(), PetscBTView()
45: S*/
46: typedef char* PetscBT;
48: extern char _BT_mask,_BT_c;
49: extern int _BT_idx;
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)
55: #define PetscBTView(m,bt,viewer) 0; {
56: int __i,__ierr;
57: PetscViewer __viewer = viewer;
58: if (!__viewer) __viewer = PETSC_VIEWER_STDOUT_SELF;
59: for (__i=0; __i<m; __i++) {
60: __PetscPrintf(((PetscObject)__viewer)->comm,"%d %dn",__i,PetscBTLookup(bt,__i));CHKERRQ(__ierr);
61: }}
63: #define PetscBTCreate(m,array) 0; {
64: int __ierr;
65: __PetscMalloc(((m)/BITSPERBYTE+1)*sizeof(char),&(array));CHKERRQ(__ierr);
66: __PetscBTMemzero(m,array);CHKERRQ(__ierr);
67: }
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)
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)
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)
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)
91: #endif