Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/stdlib.c

    r9c47a47 re672372  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 28 18:43:16 2017
    13 // Update Count     : 378
     12// Last Modified On : Sun Dec 24 13:00:15 2017
     13// Update Count     : 344
    1414//
    1515
     
    128128//---------------------------------------
    129129
    130 forall( otype E | { int ?<?( E, E ); } )
    131 E * bsearch( E key, const E * arr, size_t dim ) {
    132         int comp( const void * t1, const void * t2 ) { return *(E *)t1 < *(E *)t2 ? -1 : *(E *)t2 < *(E *)t1 ? 1 : 0; }
    133         return (E *)bsearch( &key, arr, dim, sizeof(E), comp );
     130forall( otype T | { int ?<?( T, T ); } )
     131T * bsearch( T key, const T * arr, size_t dim ) {
     132        int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
     133        return (T *)bsearch( &key, arr, dim, sizeof(T), comp );
    134134} // bsearch
    135135
    136 forall( otype E | { int ?<?( E, E ); } )
    137 unsigned int bsearch( E key, const E * arr, size_t dim ) {
    138         E * result = bsearch( key, arr, dim );
    139         return result ? result - arr : dim;                                     // pointer subtraction includes sizeof(E)
     136forall( otype T | { int ?<?( T, T ); } )
     137unsigned int bsearch( T key, const T * arr, size_t dim ) {
     138        T * result = bsearch( key, arr, dim );
     139        return result ? result - arr : dim;                                     // pointer subtraction includes sizeof(T)
    140140} // bsearch
    141141
    142 forall( otype K, otype E | { int ?<?( K, K ); K getKey( E & ); } )
    143 E * bsearch( K key, const E * arr, size_t dim ) {
    144         int comp( const void * t1, const void * t2 ) { return *(K *)t1 < getKey( *(E *)t2 ) ? -1 : getKey( *(E *)t2 ) < *(K *)t1 ? 1 : 0; }
    145         return (E *)bsearch( &key, arr, dim, sizeof(E), comp );
    146 } // bsearch
    147 
    148 forall( otype K, otype E | { int ?<?( K, K ); K getKey( E & ); } )
    149 unsigned int bsearch( K key, const E * arr, size_t dim ) {
    150         E * result = bsearch( key, arr, dim );
    151         return result ? result - arr : dim;                                     // pointer subtraction includes sizeof(E)
    152 } // bsearch
    153 
    154 forall( otype E | { int ?<?( E, E ); } )
    155 void qsort( E * arr, size_t dim ) {
    156         int comp( const void * t1, const void * t2 ) { return *(E *)t1 < *(E *)t2 ? -1 : *(E *)t2 < *(E *)t1 ? 1 : 0; }
    157         qsort( arr, dim, sizeof(E), comp );
     142forall( otype T | { int ?<?( T, T ); } )
     143void qsort( const T * arr, size_t dim ) {
     144        int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; }
     145        qsort( arr, dim, sizeof(T), comp );
    158146} // qsort
    159147
Note: See TracChangeset for help on using the changeset viewer.