Changeset 614 for trunk/psLib/src/collections/psBitSet.c
- Timestamp:
- May 7, 2004, 2:08:27 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psBitSet.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psBitSet.c
r578 r614 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-05-0 5 20:43:22$12 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-05-08 00:08:27 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 55 55 /*****************************************************************************/ 56 56 57 /** Private function to return a byte.58 *59 * Finds the byte containing the bit within the byte array.60 *61 * @return char*: Pointer to byte in which bit is contained.62 */63 static char* getByte(int bit, const psBitSet *restrict inMask)64 {65 int index = 0;66 char *byte = 0;67 index = bit/8;68 byte = inMask->bits+index;69 70 return byte;71 }72 73 57 /** Private function to create a mask. 74 58 * … … 80 64 static char mask(int bit) 81 65 { 82 char mask = 0x01; 66 char mask = (char)0x01; 67 // Ignore splint warning about negative bit shifts 68 /*@i@*/ 83 69 mask = mask << (bit%8); 84 70 … … 91 77 psBitSet* psBitSetAlloc(int n) 92 78 { 93 psBitSet *newObj = psAlloc(sizeof(psBitSet)); 79 psBitSet *newObj = NULL; 80 81 if(n <= 0) { 82 psError(__func__, " : Line %d - Allocation size must be >= 0: size = %d\n", __LINE__, n); 83 return 0; 84 } 85 86 newObj = psAlloc(sizeof(psBitSet)); 94 87 newObj->n = n; 88 89 // Ignore splint warning about releasing pointer members, since they've not been allocated yet 90 /*@i@*/ 95 91 newObj->bits = psAlloc(sizeof(char)*n); 96 92 memset(newObj->bits, n, 0); … … 101 97 void psBitSetFree(psBitSet *restrict inBitSet) 102 98 { 99 if(inBitSet == NULL) { 100 psError(__func__, " : Line %d - Null psBitSet for inBitSet argument\n", __LINE__); 101 return; 102 } 103 103 psFree(inBitSet->bits); 104 104 psFree(inBitSet); … … 107 107 psBitSet* psBitSetSet(psBitSet *inBitSet, int bit) 108 108 { 109 char* byte = getByte(bit, inBitSet); 109 char* byte = NULL; 110 111 if(inBitSet == NULL) { 112 psError(__func__, " : Line %d - Null psBitSet for inBitSet argument\n", __LINE__); 113 return inBitSet; 114 } else if(bit < 0) { 115 psError(__func__, " : Line %d - Negative bit position not allowed: %d\n", __LINE__, bit); 116 return inBitSet; 117 } 118 119 // Variable byte is the byte in the array that contains the bit to be set 120 byte = inBitSet->bits+bit/8; 110 121 *byte |= mask(bit); 111 122 … … 115 126 int psBitSetTest(const psBitSet *inBitSet, int bit) 116 127 { 117 char* byte = getByte(bit, inBitSet); 118 if((*byte&mask(bit)) == 0) { 128 char* byte = NULL; 129 130 if(inBitSet == NULL) { 131 psError(__func__, " : Line %d - Null psBitSet for inBitSet argument\n", __LINE__); 132 return 0; 133 } else if(bit < 0) { 134 psError(__func__, " : Line %d - Negative bit position not allowed: %d\n", __LINE__, bit); 135 return 0; 136 } 137 138 // Variable byte is the byte in the array that contains the bit to be tested 139 byte = inBitSet->bits+bit/8; 140 if((int)(*byte&mask(bit)) == 0) { 119 141 return 0; 120 142 } … … 191 213 int i = 0; 192 214 int numBits = inBitSet->n*8; 193 char* outString = psAlloc( numBits);215 char* outString = psAlloc((size_t)numBits); 194 216 for(i=0; i<numBits; i++) { 195 outString[numBits-i-1] = (psBitSetTest(inBitSet, i) )?'1':'0';217 outString[numBits-i-1] = (psBitSetTest(inBitSet, i) == 1)?'1':'0'; 196 218 } 197 219
Note:
See TracChangeset
for help on using the changeset viewer.
