Changeset 707446a
- Timestamp:
- Apr 1, 2017, 7:14:11 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 06cf47f
- Parents:
- 24c18ea
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/stdlib
r24c18ea r707446a 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Mar 4 22:03:54 201713 // Update Count : 10 212 // Last Modified On : Sat Apr 1 17:35:24 2017 13 // Update Count : 104 14 14 // 15 15 … … 84 84 forall( otype T | { int ?<?( T, T ); } ) 85 85 T * bsearch( T key, const T * arr, size_t dimension ); 86 forall( otype T | { int ?<?( T, T ); } ) 87 unsigned int bsearch( T key, const T * arr, size_t dimension ); 86 88 87 89 forall( otype T | { int ?<?( T, T ); } ) -
src/libcfa/stdlib.c
r24c18ea r707446a 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Mar 4 22:02:22201713 // Update Count : 1 7212 // Last Modified On : Sat Apr 1 18:31:26 2017 13 // Update Count : 181 14 14 // 15 15 … … 228 228 229 229 forall( otype T | { int ?<?( T, T ); } ) 230 unsigned int bsearch( T key, const T * arr, size_t dimension ) { 231 int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; } 232 T *result = (T *)bsearch( &key, arr, dimension, sizeof(T), comp ); 233 return result ? result - arr : dimension; // pointer subtraction includes sizeof(T) 234 } // bsearch 235 236 forall( otype T | { int ?<?( T, T ); } ) 230 237 void qsort( const T * arr, size_t dimension ) { 231 238 int comp( const void * t1, const void * t2 ) { return *(T *)t1 < *(T *)t2 ? -1 : *(T *)t2 < *(T *)t1 ? 1 : 0; } -
src/tests/.expect/searchsort.txt
r24c18ea r707446a 2 2 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3 3 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 4 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 4 5 5 6 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 7 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 6 8 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 7 9 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, … … 10 12 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11 13 10.5, 9.5, 8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 14 10.5, 9.5, 8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 12 15 13 16 10 11, 9 10, 8 9, 7 8, 6 7, 5 6, 4 5, 3 4, 2 3, 1 2, 14 17 1 2, 2 3, 3 4, 4 5, 5 6, 6 7, 7 8, 8 9, 9 10, 10 11, 15 18 10 11, 9 10, 8 9, 7 8, 6 7, 5 6, 4 5, 3 4, 2 3, 1 2, 19 10 11, 9 10, 8 9, 7 8, 6 7, 5 6, 4 5, 3 4, 2 3, 1 2, 16 20 -
src/tests/searchsort.c
r24c18ea r707446a 10 10 // Created On : Thu Feb 4 18:17:50 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 5 18:06:07 201613 // Update Count : 5612 // Last Modified On : Sat Apr 1 19:10:12 2017 13 // Update Count : 62 14 14 // 15 15 … … 35 35 sout | *v | ", "; 36 36 } // for 37 sout | endl; 38 for ( unsigned int i = 0; i < size; i += 1 ) { 39 unsigned int posn = bsearch( size - i, iarr, size ); 40 sout | iarr[posn] | ", "; 41 } // for 37 42 sout | endl | endl; 38 43 … … 54 59 sout | *v | ", "; 55 60 } // for 61 sout | endl; 62 for ( unsigned int i = 0; i < size; i += 1 ) { 63 unsigned int posn = bsearch( size - i, iarr, size ); 64 sout | iarr[posn] | ", "; 65 } // for 56 66 } 57 67 sout | endl | endl; … … 71 81 double *v = bsearch( size - i + 0.5, darr, size ); 72 82 sout | *v | ", "; 83 } // for 84 sout | endl; 85 for ( unsigned int i = 0; i < size; i += 1 ) { 86 unsigned int posn = bsearch( size - i + 0.5, darr, size ); 87 sout | darr[posn] | ", "; 73 88 } // for 74 89 sout | endl | endl; … … 93 108 sout | *v | ", "; 94 109 } // for 110 sout | endl; 111 for ( unsigned int i = 0; i < size; i += 1 ) { 112 S temp = { size - i, size - i + 1 }; 113 unsigned int posn = bsearch( temp, sarr, size ); 114 sout | sarr[posn] | ", "; 115 } // for 95 116 sout | endl | endl; 96 117 } // main
Note: See TracChangeset
for help on using the changeset viewer.