IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 2:06:06 PM (22 years ago)
Author:
desonia
Message:

another attempt to get astyle to get it right.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psBitSet.c

    r1406 r1407  
     1
    12/** @file  psBitSet.c
    23 *
     
    1011 *  @author Ross Harman, MHPCC
    1112 *
    12  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-08-06 22:34:05 $
     13 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-08-07 00:06:06 $
    1415 *
    1516 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1718
    1819/******************************************************************************/
     20
    1921/*  INCLUDE FILES                                                             */
     22
    2023/******************************************************************************/
    2124#include <string.h>
     
    3134
    3235/******************************************************************************/
     36
    3337/*  DEFINE STATEMENTS                                                         */
    34 /******************************************************************************/
    35 
    36 // None
    37 
    38 /******************************************************************************/
     38
     39/******************************************************************************/
     40
     41// None
     42
     43/******************************************************************************/
     44
    3945/*  TYPE DEFINITIONS                                                          */
    40 /******************************************************************************/
    41 
    42 // None
    43 
    44 /*****************************************************************************/
     46
     47/******************************************************************************/
     48
     49// None
     50
     51/*****************************************************************************/
     52
    4553/*  GLOBAL VARIABLES                                                         */
    46 /*****************************************************************************/
    47 
    48 // None
    49 
    50 /*****************************************************************************/
     54
     55/*****************************************************************************/
     56
     57// None
     58
     59/*****************************************************************************/
     60
    5161/*  FILE STATIC VARIABLES                                                    */
    52 /*****************************************************************************/
    53 
    54 // None
    55 
    56 /*****************************************************************************/
     62
     63/*****************************************************************************/
     64
     65// None
     66
     67/*****************************************************************************/
     68
    5769/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    58 /*****************************************************************************/
    59 static void psBitSetFree(psBitSet *restrict inBitSet);
    60 
     70
     71/*****************************************************************************/
     72static void psBitSetFree(psBitSet * restrict inBitSet);
    6173
    6274/** Private function to create a mask.
     
    7082{
    7183    char mask = (char)0x01;
     84
    7285    // Ignore splint warning about negative bit shifts
    73     /*@i@*/
    74     mask = mask << (bit%8);
     86    /* @i@ */
     87    mask = mask << (bit % 8);
    7588
    7689    return mask;
     
    7891
    7992/*****************************************************************************/
     93
    8094/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    81 /*****************************************************************************/
    82 psBitSet* psBitSetAlloc(int n)
     95
     96/*****************************************************************************/
     97psBitSet *psBitSetAlloc(int n)
    8398{
    8499    int numBytes = 0;
    85100    psBitSet *newObj = NULL;
    86101
    87     if(n <= 0) {
     102    if (n <= 0) {
    88103        psError(__func__, " : Line %d - Allocation size must be > 0: size = %d", __LINE__, n);
    89104        return 0;
    90105    }
    91106
    92     numBytes = ceil(n/8.0);
     107    numBytes = ceil(n / 8.0);
    93108    newObj = psAlloc(sizeof(psBitSet));
    94     if(newObj == NULL) {
    95         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
    96     }
    97     p_psMemSetDeallocator(newObj,(psFreeFcn)psBitSetFree);
     109    if (newObj == NULL) {
     110        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
     111    }
     112    p_psMemSetDeallocator(newObj, (psFreeFcn) psBitSetFree);
    98113    newObj->n = numBytes;
    99114
    100115    // Ignore splint warning about releasing pointer members, since they've not been allocated yet
    101     /*@i@*/
    102     newObj->bits = psAlloc(sizeof(char)*numBytes);
    103     if(newObj->bits == NULL) {
    104         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
     116    /* @i@ */
     117    newObj->bits = psAlloc(sizeof(char) * numBytes);
     118    if (newObj->bits == NULL) {
     119        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
    105120    }
    106121
     
    110125}
    111126
    112 static void psBitSetFree(psBitSet *restrict inBitSet)
    113 {
    114     if(inBitSet == NULL) {
     127static void psBitSetFree(psBitSet * restrict inBitSet)
     128{
     129    if (inBitSet == NULL) {
    115130        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    116131        return;
     
    119134}
    120135
    121 psBitSet* psBitSetSet(psBitSet *inBitSet, int bit)
    122 {
    123     char* byte = NULL;
    124 
    125     if(inBitSet == NULL) {
     136psBitSet *psBitSetSet(psBitSet * inBitSet, int bit)
     137{
     138    char *byte = NULL;
     139
     140    if (inBitSet == NULL) {
    126141        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    127142        return inBitSet;
    128     } else
    129         if(bit < 0) {
    130             psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
    131             return inBitSet;
    132         } else
    133             if(bit > inBitSet->n*8-1) {
    134                 psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
    135                 return inBitSet;
    136             }
    137 
     143    } else if (bit < 0) {
     144        psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
     145        return inBitSet;
     146    } else if (bit > inBitSet->n * 8 - 1) {
     147        psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
     148        return inBitSet;
     149    }
    138150    // Variable byte is the byte in the array that contains the bit to be set
    139     byte = inBitSet->bits+bit/8;
     151    byte = inBitSet->bits + bit / 8;
    140152    *byte |= mask(bit);
    141153
     
    143155}
    144156
    145 bool psBitSetTest(const psBitSet *inBitSet, int bit)
    146 {
    147     char* byte = NULL;
    148 
    149     if(inBitSet == NULL) {
    150         psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    151         return 0;
    152     } else
    153         if(bit < 0) {
    154             psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
    155             return 0;
    156         } else
    157             if(bit > inBitSet->n*8-1) {
    158                 psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
    159                 return 0;
    160             }
    161 
     157bool psBitSetTest(const psBitSet * inBitSet, int bit)
     158{
     159    char *byte = NULL;
     160
     161    if (inBitSet == NULL) {
     162        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
     163        return 0;
     164    } else if (bit < 0) {
     165        psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit);
     166        return 0;
     167    } else if (bit > inBitSet->n * 8 - 1) {
     168        psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit);
     169        return 0;
     170    }
    162171    // Variable byte is the byte in the array that contains the bit to be tested
    163     byte = inBitSet->bits+bit/8;
    164     if((int)(*byte&mask(bit)) == 0) {
     172    byte = inBitSet->bits + bit / 8;
     173    if ((int)(*byte & mask(bit)) == 0) {
    165174        return 0;
    166175    }
     
    169178}
    170179
    171 psBitSet* psBitSetOp(psBitSet *outBitSet, const psBitSet *restrict inBitSet1, char *operator,
    172                      const psBitSet *restrict inBitSet2)
     180psBitSet *psBitSetOp(psBitSet * outBitSet, const psBitSet * restrict inBitSet1, char *operator,
     181                     const psBitSet * restrict inBitSet2)
    173182{
    174183    int i = 0;
     
    179188    char *inBits2 = NULL;
    180189
    181     if(inBitSet1 == NULL) {
     190    if (inBitSet1 == NULL) {
    182191        psError(__func__, " : Line %d - Null psBitSet for inBitSet1 argument", __LINE__);
    183192        return outBitSet;
    184193    }
    185194
    186     if(operator == NULL) {
     195    if (operator == NULL) {
    187196        psError(__func__, " : Line %d - Null input operator\n", __LINE__);
    188197        return outBitSet;
    189198    }
    190199
    191     if(inBitSet2 == NULL) {
     200    if (inBitSet2 == NULL) {
    192201        psError(__func__, " : Line %d - Null psBitSet for inBitSet2 argument", __LINE__);
    193202        return outBitSet;
    194203    }
    195204
    196     if(outBitSet == NULL) {
    197         outBitSet = psBitSetAlloc(inBitSet1->n*8);
    198     }
    199 
    200     if(inBitSet1->n != inBitSet2->n || outBitSet->n != inBitSet1->n) {
     205    if (outBitSet == NULL) {
     206        outBitSet = psBitSetAlloc(inBitSet1->n * 8);
     207    }
     208
     209    if (inBitSet1->n != inBitSet2->n || outBitSet->n != inBitSet1->n) {
    201210        psError(__func__, " : Line %d - psBitSet sizes not the same", __LINE__);
    202211        return outBitSet;
     
    209218
    210219    tempChar = toupper(operator[0]);
    211     switch(tempChar) {
     220    switch (tempChar) {
    212221    case 'A':
    213         for(i=0; i<n; i++) {
     222        for (i = 0; i < n; i++) {
    214223            outBits[i] = inBits1[i] & inBits2[i];
    215224        }
    216225        break;
    217226    case 'O':
    218         for(i=0; i<n; i++) {
     227        for (i = 0; i < n; i++) {
    219228            outBits[i] = inBits1[i] | inBits2[i];
    220229        }
    221230        break;
    222231    case 'X':
    223         for(i=0; i<n; i++) {
     232        for (i = 0; i < n; i++) {
    224233            outBits[i] = inBits1[i] ^ inBits2[i];
    225234        }
     
    232241}
    233242
    234 psBitSet* psBitSetNot(psBitSet *outBitSet, const psBitSet *restrict inBitSet)
     243psBitSet *psBitSetNot(psBitSet * outBitSet, const psBitSet * restrict inBitSet)
    235244{
    236245    int i = 0;
     
    239248    char *inBits = NULL;
    240249
    241     if(inBitSet == NULL) {
     250    if (inBitSet == NULL) {
    242251        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__);
    243252        return outBitSet;
     
    245254
    246255    n = inBitSet->n;
    247     if(n == 0) {
     256    if (n == 0) {
    248257        psError(__func__, " : Line %d - No elements in inBitSet", __LINE__);
    249258        return outBitSet;
    250259    }
    251260
    252     if(outBitSet == NULL) {
    253         outBitSet = psBitSetAlloc(n*8);
    254     }
    255 
    256     if(inBitSet->n != outBitSet->n) {
     261    if (outBitSet == NULL) {
     262        outBitSet = psBitSetAlloc(n * 8);
     263    }
     264
     265    if (inBitSet->n != outBitSet->n) {
    257266        psError(__func__, " : Line %d - psBitSet sizes not the same", __LINE__);
    258267        return outBitSet;
     
    262271    inBits = inBitSet->bits;
    263272
    264     for(i=0; i<n; i++) {
     273    for (i = 0; i < n; i++) {
    265274        outBits[i] = ~inBits[i];
    266275    }
     
    269278}
    270279
    271 char *psBitSetToString(const psBitSet *restrict inBitSet)
     280char *psBitSetToString(const psBitSet * restrict inBitSet)
    272281{
    273282    int i = 0;
    274     int numBits = inBitSet->n*8;
    275     char* outString = psAlloc((size_t)numBits+1);
    276     if(outString == NULL) {
    277         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
    278     }
    279 
    280     for(i=0; i<numBits; i++) {
    281         outString[numBits-i-1] = (psBitSetTest(inBitSet, i) == 1)?'1':'0';
     283    int numBits = inBitSet->n * 8;
     284    char *outString = psAlloc((size_t) numBits + 1);
     285
     286    if (outString == NULL) {
     287        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
     288    }
     289
     290    for (i = 0; i < numBits; i++) {
     291        outString[numBits - i - 1] = (psBitSetTest(inBitSet, i) == 1) ? '1' : '0';
    282292    }
    283293
Note: See TracChangeset for help on using the changeset viewer.