Changeset 93cdd5c
 Timestamp:
 Jan 2, 2018, 8:34:33 AM (7 years ago)
 Branches:
 ADT, aaronthesis, armeh, astexperimental, cleanupdtors, deferred_resn, demangler, enum, forallpointerdecay, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, newenv, no_list, persistentindexer, pthreademulation, qualifiedEnum, resolvnew, with_gc
 Children:
 490d9972, f3458a8
 Parents:
 853451b
 Location:
 src
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

src/libcfa/stdlib
r853451b r93cdd5c 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Dec 28 18:43:12 201713 // Update Count : 2 7712 // Last Modified On : Mon Jan 1 17:35:43 2018 13 // Update Count : 291 14 14 // 15 15 … … 186 186 187 187 forall( otype E  { int ?<?( E, E ); } ) 188 E * bsearch( E key, const E * arr, size_t dim ); 189 190 forall( otype E  { int ?<?( E, E ); } ) 191 unsigned int bsearch( E key, const E * arr, size_t dim ); 192 193 forall( otype K, otype E  { int ?<?( K, K ); K getKey( E & ); } ) 194 E * bsearch( K key, const E * arr, size_t dim ); 195 196 forall( otype K, otype E  { int ?<?( K, K ); K getKey( E & ); } ) 197 unsigned int bsearch( K key, const E * arr, size_t dim ); 198 199 forall( otype E  { int ?<?( E, E ); } ) 200 void qsort( E * arr, size_t dim ); 188 E * bsearch( E key, const E * vals, size_t dim ); 189 190 forall( otype E  { int ?<?( E, E ); } ) 191 size_t bsearch( E key, const E * vals, size_t dim ); 192 193 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 194 E * bsearch( K key, const E * vals, size_t dim ); 195 196 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 197 size_t bsearch( K key, const E * vals, size_t dim ); 198 199 200 forall( otype E  { int ?<?( E, E ); } ) 201 E * bsearchl( E key, const E * vals, size_t dim ); 202 203 forall( otype E  { int ?<?( E, E ); } ) 204 size_t bsearchl( E key, const E * vals, size_t dim ); 205 206 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 207 E * bsearchl( K key, const E * vals, size_t dim ); 208 209 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 210 size_t bsearchl( K key, const E * vals, size_t dim ); 211 212 213 forall( otype E  { int ?<?( E, E ); } ) 214 E * bsearchu( E key, const E * vals, size_t dim ); 215 216 forall( otype E  { int ?<?( E, E ); } ) 217 size_t bsearchu( E key, const E * vals, size_t dim ); 218 219 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 220 E * bsearchu( K key, const E * vals, size_t dim ); 221 222 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 223 size_t bsearchu( K key, const E * vals, size_t dim ); 224 225 226 forall( otype E  { int ?<?( E, E ); } ) 227 void qsort( E * vals, size_t dim ); 201 228 202 229 // 
src/libcfa/stdlib.c
r853451b r93cdd5c 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Dec 28 18:43:16 201713 // Update Count : 37812 // Last Modified On : Mon Jan 1 19:03:16 2018 13 // Update Count : 437 14 14 // 15 15 … … 129 129 130 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 ); 134 } // bsearch 135 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) 140 } // bsearch 141 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 ); 131 E * bsearch( E key, const E * vals, size_t dim ) { 132 int cmp( const void * t1, const void * t2 ) { 133 return *(E *)t1 < *(E *)t2 ? 1 : *(E *)t2 < *(E *)t1 ? 1 : 0; 134 } // cmp 135 return (E *)bsearch( &key, vals, dim, sizeof(E), cmp ); 136 } // bsearch 137 138 forall( otype E  { int ?<?( E, E ); } ) 139 size_t bsearch( E key, const E * vals, size_t dim ) { 140 E * result = bsearch( key, vals, dim ); 141 return result ? result  vals : dim; // pointer subtraction includes sizeof(E) 142 } // bsearch 143 144 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 145 E * bsearch( K key, const E * vals, size_t dim ) { 146 int cmp( const void * t1, const void * t2 ) { 147 return *(K *)t1 < getKey( *(E *)t2 ) ? 1 : getKey( *(E *)t2 ) < *(K *)t1 ? 1 : 0; 148 } // cmp 149 return (E *)bsearch( &key, vals, dim, sizeof(E), cmp ); 150 } // bsearch 151 152 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 153 size_t bsearch( K key, const E * vals, size_t dim ) { 154 E * result = bsearch( key, vals, dim ); 155 return result ? result  vals : dim; // pointer subtraction includes sizeof(E) 156 } // bsearch 157 158 159 forall( otype E  { int ?<?( E, E ); } ) 160 size_t bsearchl( E key, const E * vals, size_t dim ) { 161 size_t l = 0, m, h = dim; 162 while ( l < h ) { 163 m = (l + h) / 2; 164 if ( (E &)(vals[m]) < key ) { // cast away const 165 l = m + 1; 166 } else { 167 h = m; 168 } // if 169 } // while 170 return l; 171 } // bsearchl 172 173 forall( otype E  { int ?<?( E, E ); } ) 174 E * bsearchl( E key, const E * vals, size_t dim ) { 175 size_t posn = bsearchl( key, vals, dim ); 176 return (E *)(&vals[posn]); // cast away const 177 } // bsearchl 178 179 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 180 size_t bsearchl( K key, const E * vals, size_t dim ) { 181 size_t l = 0, m, h = dim; 182 while ( l < h ) { 183 m = (l + h) / 2; 184 if ( getKey( vals[m] ) < key ) { 185 l = m + 1; 186 } else { 187 h = m; 188 } // if 189 } // while 190 return l; 191 } // bsearchl 192 193 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 194 E * bsearchl( K key, const E * vals, size_t dim ) { 195 size_t posn = bsearchl( key, vals, dim ); 196 return (E *)(&vals[posn]); // cast away const 197 } // bsearchl 198 199 200 forall( otype E  { int ?<?( E, E ); } ) 201 size_t bsearchu( E key, const E * vals, size_t dim ) { 202 size_t l = 0, m, h = dim; 203 while ( l < h ) { 204 m = (l + h) / 2; 205 if ( ! ( key < (E &)(vals[m]) ) ) { // cast away const 206 l = m + 1; 207 } else { 208 h = m; 209 } // if 210 } // while 211 return l; 212 } // bsearchu 213 214 forall( otype E  { int ?<?( E, E ); } ) 215 E * bsearchu( E key, const E * vals, size_t dim ) { 216 size_t posn = bsearchu( key, vals, dim ); 217 return (E *)(&vals[posn]); 218 } // bsearchu 219 220 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 221 size_t bsearchu( K key, const E * vals, size_t dim ) { 222 size_t l = 0, m, h = dim; 223 while ( l < h ) { 224 m = (l + h) / 2; 225 if ( ! ( key < getKey( vals[m] ) ) ) { 226 l = m + 1; 227 } else { 228 h = m; 229 } // if 230 } // while 231 return l; 232 } // bsearchu 233 234 forall( otype K, otype E  { int ?<?( K, K ); K getKey( const E & ); } ) 235 E * bsearchu( K key, const E * vals, size_t dim ) { 236 size_t posn = bsearchu( key, vals, dim ); 237 return (E *)(&vals[posn]); 238 } // bsearchu 239 240 241 forall( otype E  { int ?<?( E, E ); } ) 242 void qsort( E * vals, size_t dim ) { 243 int cmp( const void * t1, const void * t2 ) { 244 return *(E *)t1 < *(E *)t2 ? 1 : *(E *)t2 < *(E *)t1 ? 1 : 0; 245 } // cmp 246 qsort( vals, dim, sizeof(E), cmp ); 158 247 } // qsort 159 248 
src/tests/searchsort.c
r853451b r93cdd5c 10 10 // Created On : Thu Feb 4 18:17:50 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Dec 28 18:48:10 201713 // Update Count : 9912 // Last Modified On : Tue Jan 2 08:01:17 2018 13 // Update Count : 100 14 14 // 15 15 … … 128 128 sout  endl  endl; 129 129 { 130 unsigned int getKey( S & s ) { return s.j; }130 unsigned int getKey( const S & s ) { return s.j; } 131 131 for ( unsigned int i = 0; i < size; i += 1 ) { 132 132 sout  sarr[i]  ", ";
Note: See TracChangeset
for help on using the changeset viewer.