Changes in / [853451b:d9ff69a]
- Location:
- src
- Files:
-
- 4 edited
-
libcfa/stdlib (modified) (2 diffs)
-
libcfa/stdlib.c (modified) (2 diffs)
-
tests/.expect/searchsort.txt (modified) (1 diff)
-
tests/searchsort.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/stdlib
r853451b rd9ff69a 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 : Sat Dec 23 18:21:42 2017 13 // Update Count : 267 14 14 // 15 15 … … 185 185 //--------------------------------------- 186 186 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 ); 187 forall( otype T | { int ?<?( T, T ); } ) 188 T * bsearch( T key, const T * arr, size_t dim ); 189 190 forall( otype T | { int ?<?( T, T ); } ) 191 unsigned int bsearch( T key, const T * arr, size_t dim ); 192 193 194 forall( otype T | { int ?<?( T, T ); } ) 195 void qsort( const T * arr, size_t dim ); 201 196 202 197 //--------------------------------------- -
src/libcfa/stdlib.c
r853451b rd9ff69a 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:16201713 // Update Count : 3 7812 // Last Modified On : Sun Dec 24 13:00:15 2017 13 // Update Count : 344 14 14 // 15 15 … … 128 128 //--------------------------------------- 129 129 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 );130 forall( otype T | { int ?<?( T, T ); } ) 131 T * 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 ); 134 134 } // bsearch 135 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)136 forall( otype T | { int ?<?( T, T ); } ) 137 unsigned 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) 140 140 } // bsearch 141 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 ); 142 forall( otype T | { int ?<?( T, T ); } ) 143 void 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 ); 158 146 } // qsort 159 147 -
src/tests/.expect/searchsort.txt
r853451b rd9ff69a 2 2 3 3 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 4 10 :10, 9:9, 8:8, 7:7, 6:6, 5:5, 4:4, 3:3, 2:2, 1:1,5 10 :10, 9:9, 8:8, 7:7, 6:6, 5:5, 4:4, 3:3, 2:2, 1:1,6 10 :10, 9:9, 8:8, 7:7, 6:6, 5:5, 4:4, 3:3, 2:2, 1:1,4 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 5 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 6 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 7 7 8 8 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9 9 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10 10 :10, 9:9, 8:8, 7:7, 6:6, 5:5, 4:4, 3:3, 2:2, 1:1,11 10 :10, 9:9, 8:8, 7:7, 6:6, 5:5, 4:4, 3:3, 2:2, 1:1,10 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12 12 13 13 10.5, 9.5, 8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 14 14 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 15 10.5 :10.5, 9.5:9.5, 8.5:8.5, 7.5:7.5, 6.5:6.5, 5.5:5.5, 4.5:4.5, 3.5:3.5, 2.5:2.5, 1.5:1.5,16 10.5 :10.5, 9.5:9.5, 8.5:8.5, 7.5:7.5, 6.5:6.5, 5.5:5.5, 4.5:4.5, 3.5:3.5, 2.5:2.5, 1.5:1.5,15 10.5, 9.5, 8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 16 10.5, 9.5, 8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 17 17 18 18 10 11, 9 10, 8 9, 7 8, 6 7, 5 6, 4 5, 3 4, 2 3, 1 2, 19 19 1 2, 2 3, 3 4, 4 5, 5 6, 6 7, 7 8, 8 9, 9 10, 10 11, 20 10 11 :10 11, 9 10:9 10, 8 9:8 9, 7 8:7 8, 6 7:6 7, 5 6:5 6, 4 5:4 5, 3 4:3 4, 2 3:2 3, 1 2:1 2,21 10 11 :10 11, 9 10:9 10, 8 9:8 9, 7 8:7 8, 6 7:6 7, 5 6:5 6, 4 5:4 5, 3 4:3 4, 2 3:2 3, 1 2:1 2,20 10 11, 9 10, 8 9, 7 8, 6 7, 5 6, 4 5, 3 4, 2 3, 1 2, 21 10 11, 9 10, 8 9, 7 8, 6 7, 5 6, 4 5, 3 4, 2 3, 1 2, 22 22 23 1 2, 2 3, 3 4, 4 5, 5 6, 6 7, 7 8, 8 9, 9 10, 10 11,24 11:10 11, 10:9 10, 9:8 9, 8:7 8, 7:6 7, 6:5 6, 5:4 5, 4:3 4, 3:2 3, 2:1 2,25 11:10 11, 10:9 10, 9:8 9, 8:7 8, 7:6 7, 6:5 6, 5:4 5, 4:3 4, 3:2 3, 2:1 2,26 -
src/tests/searchsort.c
r853451b rd9ff69a 10 10 // Created On : Thu Feb 4 18:17:50 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Dec 28 18:48:10201713 // Update Count : 9912 // Last Modified On : Thu Dec 7 09:14:06 2017 13 // Update Count : 77 14 14 // 15 15 … … 38 38 for ( unsigned int i = 0; i < size; i += 1 ) { // C version 39 39 int key = size - i; 40 int * v = bsearch( &key, iarr, size, sizeof( iarr[0] ), comp );41 sout | key | ':' |*v | ", ";40 int *v = bsearch( &key, iarr, size, sizeof( iarr[0] ), comp ); 41 sout | *v | ", "; 42 42 } // for 43 43 sout | endl; 44 45 44 for ( unsigned int i = 0; i < size; i += 1 ) { 46 int * v = bsearch( size - i, iarr, size );47 sout | size - i | ':' |*v | ", ";45 int *v = bsearch( size - i, iarr, size ); 46 sout | *v | ", "; 48 47 } // for 49 48 sout | endl; 50 49 for ( unsigned int i = 0; i < size; i += 1 ) { 51 50 unsigned int posn = bsearch( size - i, iarr, size ); 52 sout | size - i | ':' |iarr[posn] | ", ";51 sout | iarr[posn] | ", "; 53 52 } // for 54 53 sout | endl | endl; … … 68 67 sout | endl; 69 68 for ( unsigned int i = 0; i < size; i += 1 ) { 70 int * v = bsearch( size - i, iarr, size );71 sout | size - i | ':' |*v | ", ";69 int *v = bsearch( size - i, iarr, size ); 70 sout | *v | ", "; 72 71 } // for 73 72 sout | endl; 74 73 for ( unsigned int i = 0; i < size; i += 1 ) { 75 74 unsigned int posn = bsearch( size - i, iarr, size ); 76 sout | size - i | ':' |iarr[posn] | ", ";75 sout | iarr[posn] | ", "; 77 76 } // for 78 77 } … … 91 90 sout | endl; 92 91 for ( unsigned int i = 0; i < size; i += 1 ) { 93 double * v = bsearch( size - i + 0.5, darr, size );94 sout | size - i + 0.5 | ':' |*v | ", ";92 double *v = bsearch( size - i + 0.5, darr, size ); 93 sout | *v | ", "; 95 94 } // for 96 95 sout | endl; 97 96 for ( unsigned int i = 0; i < size; i += 1 ) { 98 97 unsigned int posn = bsearch( size - i + 0.5, darr, size ); 99 sout | size - i + 0.5 | ':' |darr[posn] | ", ";98 sout | darr[posn] | ", "; 100 99 } // for 101 100 sout | endl | endl; … … 117 116 for ( unsigned int i = 0; i < size; i += 1 ) { 118 117 S temp = { size - i, size - i + 1 }; 119 S * v = bsearch( temp, sarr, size );120 sout | temp | ':' |*v | ", ";118 S *v = bsearch( temp, sarr, size ); 119 sout | *v | ", "; 121 120 } // for 122 121 sout | endl; … … 124 123 S temp = { size - i, size - i + 1 }; 125 124 unsigned int posn = bsearch( temp, sarr, size ); 126 sout | temp | ':' |sarr[posn] | ", ";125 sout | sarr[posn] | ", "; 127 126 } // for 128 127 sout | endl | endl; 129 {130 unsigned int getKey( S & s ) { return s.j; }131 for ( unsigned int i = 0; i < size; i += 1 ) {132 sout | sarr[i] | ", ";133 } // for134 sout | endl;135 for ( unsigned int i = 0; i < size; i += 1 ) {136 S * v = bsearch( size - i + 1, sarr, size );137 sout | size - i + 1 | ':' | *v | ", ";138 } // for139 sout | endl;140 for ( unsigned int i = 0; i < size; i += 1 ) {141 unsigned int posn = bsearch( size - i + 1, sarr, size );142 sout | size - i + 1 | ':' | sarr[posn] | ", ";143 } // for144 sout | endl | endl;145 }146 128 } // main 147 129
Note:
See TracChangeset
for help on using the changeset viewer.