1 /* $Id: bitarray.h,v 1.3 1996/02/01 15:36:30 balay Exp balay $ */ 2 3 /* 4 BT_LOOKUP - Expexts a charecter array -'array' as input, and 5 treats it as an array of bits. It Checks if a given bit location 6 ( specified by 'index') is marked, and later marks that location. 7 8 Input: 9 array - an array of char. Initially all bits are to be set to zero 10 by using PetscMemzero(). 11 index - specifies the index of the required bit in the bit array. 12 13 Output: 14 return val - 0 if the bit is not found, 15 - nonzero if found. 16 17 Usage : 18 BT_LOOKUP(char * array, int index) ; 19 20 Summary: 21 The bit operations are euivalent to: 22 1: retval = array[idx]; 23 2: array[index] = 1; 24 3: return retval; 25 */ 26 #include <values.h> 27 static char _mask, _BT_c; 28 static int _BT_idx; 29 #define BT_LOOKUP( array, index) (_BT_idx = index/BITSPERBYTE, \ 30 _BT_c = array[_BT_idx], \ 31 _BT_idx = index/BITSPERBYTE, \ 32 _mask = (char)1 << (index%BITSPERBYTE), \ 33 array[_BT_idx] = _BT_c|_mask, \ 34 _BT_c & _mask ) 35 36 37