IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 4, 2004, 1:37:39 PM (22 years ago)
Author:
desonia
Message:

found the server astyle upgrade was faulty, so the format was reset.

File:
1 edited

Legend:

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

    r1360 r1385  
    88*  @author Ross Harman, MHPCC
    99*
    10 *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2004-07-31 02:28:10 $
     10*  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2004-08-04 23:37:39 $
    1212*
    1313*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6363    psVector * psVec = NULL;
    6464    int elementSize = 0;
    65    
     65
    6666    // Invalid nalloc
    6767    if ( nalloc < 1 ) {
    68             psError( __func__, "Invalid value for nalloc. nalloc: %d\n", nalloc );
    69             return NULL;
    70         }
    71        
     68        psError( __func__, "Invalid value for nalloc. nalloc: %d\n", nalloc );
     69        return NULL;
     70    }
     71
    7272    elementSize = PSELEMTYPE_SIZEOF( elemType );
    73    
     73
    7474    // Create vector struct
    7575    psVec = ( psVector * ) psAlloc( sizeof( psVector ) );
    7676    p_psMemSetDeallocator( psVec, ( psFreeFcn ) vectorFree );
    77    
     77
    7878    psVec->type.dimen = PS_DIMEN_VECTOR;
    7979    psVec->type.type = elemType;
    8080    psVec->nalloc = nalloc;
    8181    psVec->n = nalloc;
    82    
     82
    8383    // Create vector data array
    8484    psVec->data.V = psAlloc( nalloc * elementSize );
    85    
     85
    8686    return psVec;
    8787}
     
    9191    int elementSize = 0;
    9292    psElemType elemType;
    93    
     93
    9494    // Invalid nalloc
    9595    if ( nalloc < 1 ) {
    96             psError( __func__, "Invalid value for realloc (%d)\n", nalloc );
    97             return NULL;
    98         }
    99        
     96        psError( __func__, "Invalid value for realloc (%d)\n", nalloc );
     97        return NULL;
     98    }
     99
    100100    if ( in == NULL ) {
    101             psError( __func__, "Null input vector\n" );
    102             return NULL;
    103         } else if ( in->nalloc != nalloc ) {                    // No need to realloc to same size
     101        psError( __func__, "Null input vector\n" );
     102        return NULL;
     103    } else
     104        if ( in->nalloc != nalloc ) {                    // No need to realloc to same size
    104105            elemType = in->type.type;
    105106            elementSize = PSELEMTYPE_SIZEOF( elemType );
    106107            if ( nalloc < in->n ) {
    107                     in->n = nalloc;
    108                 }
    109                
     108                in->n = nalloc;
     109            }
     110
    110111            // Realloc after decrementation to avoid accessing freed array elements
    111112            in->data.V = psRealloc( in->data.V, nalloc * elementSize );
    112113            in->nalloc = nalloc;
    113114        }
    114        
     115
    115116    return in;
    116117}
     
    119120{
    120121    psElemType elemType;
    121    
     122
    122123    if ( in == NULL ) {
    123             return psVectorAlloc( nalloc, type );
    124         }
    125        
     124        return psVectorAlloc( nalloc, type );
     125    }
     126
    126127    elemType = in->type.type;
    127    
     128
    128129    if ( in->nalloc == nalloc && elemType == type ) {
    129             // it is proper size/type already
    130             return in;
    131         }
    132        
     130        // it is proper size/type already
     131        return in;
     132    }
     133
    133134    // Invalid nalloc
    134135    if ( nalloc < 1 ) {
    135             psError( __func__, "Invalid value for nalloc (%d)\n", nalloc );
    136             psFree( in );
    137             return NULL;
    138         }
    139        
    140        
     136        psError( __func__, "Invalid value for nalloc (%d)\n", nalloc );
     137        psFree( in );
     138        return NULL;
     139    }
     140
     141
    141142    in->data.V = psRealloc( in->data.V, nalloc * PSELEMTYPE_SIZEOF( type ) );
    142    
     143
    143144    in->type.type = type;
    144145    in->nalloc = nalloc;
    145146    in->n = nalloc;
    146    
     147
    147148    return in;
    148149}
     
    156157    void *outVec = NULL;
    157158    psElemType inType = 0;
    158    
     159
    159160    if ( inVector == NULL ) {
    160             psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
    161             return outVector;
    162         }
    163        
     161        psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
     162        return outVector;
     163    }
     164
    164165    inType = inVector->type.type;
    165166    inN = inVector->n;
    166167    inVec = inVector->data.V;
    167168    elSize = PSELEMTYPE_SIZEOF( inType );
    168    
     169
    169170    if ( outVector == NULL ) {
    170             outVector = psVectorAlloc( inN, inType );
    171             outVector->n = inVector->n;
    172         }
    173        
     171        outVector = psVectorAlloc( inN, inType );
     172        outVector->n = inVector->n;
     173    }
     174
    174175    outN = outVector->n;
    175176    outVec = outVector->data.V;
    176    
     177
    177178    if ( inN != outN ) {
    178             psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
    179                      inN, outN );
    180             return outVector;
    181         }
    182        
     179        psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
     180                 inN, outN );
     181        return outVector;
     182    }
     183
    183184    if ( inType != outVector->type.type ) {
    184             psError( __func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
    185                      inType, outVector->type.type );
    186             return outVector;
    187         }
    188        
     185        psError( __func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
     186                 inType, outVector->type.type );
     187        return outVector;
     188    }
     189
    189190    if ( inN == 0 ) {
    190             psError( __func__, " : Line %d - No elements in use for input vector\n", __LINE__ );
    191             return outVector;
    192         }
    193        
     191        psError( __func__, " : Line %d - No elements in use for input vector\n", __LINE__ );
     192        return outVector;
     193    }
     194
    194195    if ( outN == 0 ) {
    195             psError( __func__, " : Line %d - No elements in use for output vector\n", __LINE__ );
    196             return outVector;
    197         }
    198        
     196        psError( __func__, " : Line %d - No elements in use for output vector\n", __LINE__ );
     197        return outVector;
     198    }
     199
    199200    // Copy input vector values into output vector
    200201    memcpy( outVec, inVec, elSize * outN );
    201    
     202
    202203    // Sort output vector
    203204    switch ( inType ) {
    204             case PS_TYPE_U8:
    205             qsort( outVec, inN, elSize, psCompareU8 );
    206             break;
    207             case PS_TYPE_U16:
    208             qsort( outVec, inN, elSize, psCompareU16 );
    209             break;
    210             case PS_TYPE_U32:
    211             qsort( outVec, inN, elSize, psCompareU32 );
    212             break;
    213             case PS_TYPE_U64:
    214             qsort( outVec, inN, elSize, psCompareU64 );
    215             break;
    216             case PS_TYPE_S8:
    217             qsort( outVec, inN, elSize, psCompareS8 );
    218             break;
    219             case PS_TYPE_S16:
    220             qsort( outVec, inN, elSize, psCompareS16 );
    221             break;
    222             case PS_TYPE_S32:
    223             qsort( outVec, inN, elSize, psCompareS32 );
    224             break;
    225             case PS_TYPE_S64:
    226             qsort( outVec, inN, elSize, psCompareS64 );
    227             break;
    228             case PS_TYPE_F32:
    229             qsort( outVec, inN, elSize, psCompareF32 );
    230             break;
    231             case PS_TYPE_F64:
    232             qsort( outVec, inN, elSize, psCompareF64 );
    233             break;
    234             default:
    235             psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
    236         }
    237        
     205    case PS_TYPE_U8:
     206        qsort( outVec, inN, elSize, psCompareU8 );
     207        break;
     208    case PS_TYPE_U16:
     209        qsort( outVec, inN, elSize, psCompareU16 );
     210        break;
     211    case PS_TYPE_U32:
     212        qsort( outVec, inN, elSize, psCompareU32 );
     213        break;
     214    case PS_TYPE_U64:
     215        qsort( outVec, inN, elSize, psCompareU64 );
     216        break;
     217    case PS_TYPE_S8:
     218        qsort( outVec, inN, elSize, psCompareS8 );
     219        break;
     220    case PS_TYPE_S16:
     221        qsort( outVec, inN, elSize, psCompareS16 );
     222        break;
     223    case PS_TYPE_S32:
     224        qsort( outVec, inN, elSize, psCompareS32 );
     225        break;
     226    case PS_TYPE_S64:
     227        qsort( outVec, inN, elSize, psCompareS64 );
     228        break;
     229    case PS_TYPE_F32:
     230        qsort( outVec, inN, elSize, psCompareF32 );
     231        break;
     232    case PS_TYPE_F64:
     233        qsort( outVec, inN, elSize, psCompareF64 );
     234        break;
     235    default:
     236        psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
     237    }
     238
    238239    return outVector;
    239240}
     
    241242#define SORT_INDICES(TYPE)                                                                                   \
    242243for(i=0; i<inN; i++) {                                                                                       \
    243         for(j=0; j<inN; j++) {                                                                                   \
    244                 diff = fabs((double)tmpVector->data.TYPE[i] - inVec[j]);                                             \
    245                 if(diff < FLT_EPSILON) {                                                                             \
    246                         outVec[i] = j;                                                                                   \
    247                         break;                                                                                           \
    248                     }                                                                                                    \
    249             }                                                                                                        \
    250     }
    251    
     244    for(j=0; j<inN; j++) {                                                                                   \
     245        diff = fabs((double)tmpVector->data.TYPE[i] - inVec[j]);                                             \
     246        if(diff < FLT_EPSILON) {                                                                             \
     247            outVec[i] = j;                                                                                   \
     248            break;                                                                                           \
     249        }                                                                                                    \
     250    }                                                                                                        \
     251}
     252
    252253psVector *psVectorSortIndex( psVector *restrict outVector, const psVector *restrict inVector )
    253254{
     
    261262    psVector *tmpVector = NULL;
    262263    psElemType inType = 0;
    263    
     264
    264265    if ( inVector == NULL ) {
    265             psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
    266             return outVector;
    267         }
    268        
     266        psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
     267        return outVector;
     268    }
     269
    269270    inN = inVector->n;
    270271    inVec = inVector->data.V;
    271272    inType = inVector->type.type;
    272    
     273
    273274    if ( outVector == NULL ) {
    274             outVector = psVectorAlloc( inN, PS_TYPE_U32 );
    275             outVector->n = inN;
    276         }
    277        
     275        outVector = psVectorAlloc( inN, PS_TYPE_U32 );
     276        outVector->n = inN;
     277    }
     278
    278279    outN = outVector->n;
    279280    outVec = outVector->data.V;
    280    
     281
    281282    if ( inN != outN ) {
    282             psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
    283                      __LINE__, inN, outN );
    284             return outVector;
    285         }
    286        
     283        psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
     284                 __LINE__, inN, outN );
     285        return outVector;
     286    }
     287
    287288    if ( outVector->type.type != PS_TYPE_U32 ) {
    288             psError( __func__, " : Line %d - Output vector is not of type U32: out=%d\n",
    289                      __LINE__, outVector->type.type );
    290             return outVector;
    291         }
    292        
     289        psError( __func__, " : Line %d - Output vector is not of type U32: out=%d\n",
     290                 __LINE__, outVector->type.type );
     291        return outVector;
     292    }
     293
    293294    tmpVector = psVectorAlloc( inN, inType );
    294295    tmpVector->n = inN;
    295296    tmpVector = psVectorSort( tmpVector, inVector );
    296    
     297
    297298    // Sort output vector
    298299    switch ( inType ) {
    299             case PS_TYPE_U8:
    300             SORT_INDICES( U8 );
    301             break;
    302             case PS_TYPE_U16:
    303             SORT_INDICES( U16 );
    304             break;
    305             case PS_TYPE_U32:
    306             SORT_INDICES( U32 );
    307             break;
    308             case PS_TYPE_U64:
    309             SORT_INDICES( U64 );
    310             break;
    311             case PS_TYPE_S8:
    312             SORT_INDICES( S8 );
    313             break;
    314             case PS_TYPE_S16:
    315             SORT_INDICES( S16 );
    316             break;
    317             case PS_TYPE_S32:
    318             SORT_INDICES( S32 );
    319             break;
    320             case PS_TYPE_S64:
    321             SORT_INDICES( S64 );
    322             break;
    323             case PS_TYPE_F32:
    324             SORT_INDICES( F32 );
    325             break;
    326             case PS_TYPE_F64:
    327             SORT_INDICES( F64 );
    328             break;
    329             default:
    330             psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
    331         }
    332        
     300    case PS_TYPE_U8:
     301        SORT_INDICES( U8 );
     302        break;
     303    case PS_TYPE_U16:
     304        SORT_INDICES( U16 );
     305        break;
     306    case PS_TYPE_U32:
     307        SORT_INDICES( U32 );
     308        break;
     309    case PS_TYPE_U64:
     310        SORT_INDICES( U64 );
     311        break;
     312    case PS_TYPE_S8:
     313        SORT_INDICES( S8 );
     314        break;
     315    case PS_TYPE_S16:
     316        SORT_INDICES( S16 );
     317        break;
     318    case PS_TYPE_S32:
     319        SORT_INDICES( S32 );
     320        break;
     321    case PS_TYPE_S64:
     322        SORT_INDICES( S64 );
     323        break;
     324    case PS_TYPE_F32:
     325        SORT_INDICES( F32 );
     326        break;
     327    case PS_TYPE_F64:
     328        SORT_INDICES( F64 );
     329        break;
     330    default:
     331        psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
     332    }
     333
    333334    // Free temp memory
    334335    psFree( tmpVector );
    335    
     336
    336337    return outVector;
    337338}
     
    340341{
    341342    if ( psVec == NULL ) {
    342             return ;
    343         }
    344        
     343        return ;
     344    }
     345
    345346    psFree( psVec->data.V );
    346347}
Note: See TracChangeset for help on using the changeset viewer.