Changeset 25cdca5 for tests/searchsort.cfa
 Timestamp:
 Jan 8, 2019, 11:31:21 AM (3 years ago)
 Branches:
 aaronthesis, armeh, cleanupdtors, deferred_resn, jacob/cs343translation, jenkinssandbox, master, newast, newastuniqueexpr, no_list, persistentindexer
 Children:
 08222c7, 274da98
 Parents:
 84b4d607 (diff), d5b2ac8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent.  File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

tests/searchsort.cfa
r84b4d607 r25cdca5 10 10 // Created On : Thu Feb 4 18:17:50 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 5 08:18:42201813 // Update Count : 10 612 // Last Modified On : Thu Dec 20 22:49:46 2018 13 // Update Count : 108 14 14 // 15 15 … … 21 21 22 22 int main( void ) { 23 const unsignedint size = 10;23 const int size = 10; 24 24 int iarr[size]; 25 25 26 26 sout  nlOff; // turn off auto newline 27 27 28 for ( i; 0 u~ size ) {28 for ( i; 0 ~ size ) { 29 29 iarr[i] = size  i; 30 30 sout  iarr[i]  ", "; 31 31 } // for 32 sout  nl ;32 sout  nl  nl; 33 33 34 34 // ascending sort/search by changing < to > 35 35 qsort( iarr, size ); 36 for ( i; 0 u~ size ) {36 for ( i; 0 ~ size ) { 37 37 sout  iarr[i]  ", "; 38 38 } // for 39 39 sout  nl; 40 for ( i; 0 u~ size ) { // C version40 for ( i; 0 ~ size ) { // C version 41 41 int key = size  i; 42 42 int * v = bsearch( &key, iarr, size, sizeof( iarr[0] ), comp ); … … 45 45 sout  nl; 46 46 47 for ( i; 0 u~ size ) {47 for ( i; 0 ~ size ) { 48 48 int * v = bsearch( size  i, iarr, size ); 49 49 sout  size  i  ':'  *v  ", "; 50 50 } // for 51 51 sout  nl; 52 for ( i; 0 u~ size ) {52 for ( i; 0 ~ size ) { 53 53 unsigned int posn = bsearch( size  i, iarr, size ); 54 54 sout  size  i  ':'  iarr[posn]  ", "; 55 55 } // for 56 sout  nl ;56 sout  nl  nl; 57 57 58 58 // descending sort/search by changing < to > … … 63 63 sout  nl; 64 64 { 65 int ?<?( int x, int y ) { return x > y; } 66 qsort( iarr, size ); 67 for ( i; 0u ~ size ) { 65 // redefinition of ?<? can't overlap the loop controls: 66 { 67 int (*?<?)(int, int) = ?>?; 68 qsort( iarr, size ); 69 } 70 for ( i; 0 ~ size ) { 68 71 sout  iarr[i]  ", "; 69 72 } // for 70 73 sout  nl; 71 for ( i; 0u ~ size ) { 74 for ( i; 0 ~ size ) { 75 int (*?<?)(int, int) = ?>?; 72 76 int * v = bsearch( size  i, iarr, size ); 73 77 sout  size  i  ':'  *v  ", "; 74 78 } // for 75 79 sout  nl; 76 for ( i; 0u ~ size ) { 80 for ( i; 0 ~ size ) { 81 int (*?<?)(int, int) = ?>?; 77 82 unsigned int posn = bsearch( size  i, iarr, size ); 78 83 sout  size  i  ':'  iarr[posn]  ", "; 79 84 } // for 80 85 } 81 sout  nl ;86 sout  nl  nl; 82 87 83 88 double darr[size]; 84 for ( i; 0 u~ size ) {89 for ( i; 0 ~ size ) { 85 90 darr[i] = size  i + 0.5; 86 91 sout  darr[i]  ", "; … … 88 93 sout  nl; 89 94 qsort( darr, size ); 90 for ( i; 0 u~ size ) {95 for ( i; 0 ~ size ) { 91 96 sout  darr[i]  ", "; 92 97 } // for 93 98 sout  nl; 94 for ( i; 0 u~ size ) {99 for ( i; 0 ~ size ) { 95 100 double * v = bsearch( size  i + 0.5, darr, size ); 96 101 sout  size  i + 0.5  ':'  *v  ", "; 97 102 } // for 98 103 sout  nl; 99 for ( i; 0 u~ size ) {104 for ( i; 0 ~ size ) { 100 105 unsigned int posn = bsearch( size  i + 0.5, darr, size ); 101 106 sout  size  i + 0.5  ':'  darr[posn]  ", "; 102 107 } // for 103 sout  nl ;108 sout  nl  nl; 104 109 105 110 struct S { int i, j; } sarr[size]; 106 111 int ?<?( S t1, S t2 ) { return t1.i < t2.i && t1.j < t2.j; } 107 112 ofstream & ??( ofstream & os, S v ) { return os  v.i  ' '  v.j; } 108 for ( i; 0 u~ size ) {113 for ( i; 0 ~ size ) { 109 114 sarr[i].i = size  i; 110 115 sarr[i].j = size  i + 1; … … 113 118 sout  nl; 114 119 qsort( sarr, size ); 115 for ( i; 0 u~ size ) {120 for ( i; 0 ~ size ) { 116 121 sout  sarr[i]  ", "; 117 122 } // for 118 123 sout  nl; 119 for ( i; 0 u~ size ) {124 for ( i; 0 ~ size ) { 120 125 S temp = { size  i, size  i + 1 }; 121 126 S * v = bsearch( temp, sarr, size ); … … 123 128 } // for 124 129 sout  nl; 125 for ( i; 0 u~ size ) {130 for ( i; 0 ~ size ) { 126 131 S temp = { size  i, size  i + 1 }; 127 132 unsigned int posn = bsearch( temp, sarr, size ); 128 133 sout  temp  ':'  sarr[posn]  ", "; 129 134 } // for 130 sout  nl ;135 sout  nl  nl; 131 136 { 132 unsignedint getKey( const S & s ) { return s.j; }133 for ( i; 0 u~ size ) {137 int getKey( const S & s ) { return s.j; } 138 for ( i; 0 ~ size ) { 134 139 sout  sarr[i]  ", "; 135 140 } // for 136 141 sout  nl; 137 for ( i; 0 u~ size ) {142 for ( i; 0 ~ size ) { 138 143 S * v = bsearch( size  i + 1, sarr, size ); 139 144 sout  size  i + 1  ':'  *v  ", "; 140 145 } // for 141 146 sout  nl; 142 for ( i; 0 u~ size ) {147 for ( i; 0 ~ size ) { 143 148 unsigned int posn = bsearch( size  i + 1, sarr, size ); 144 149 sout  size  i + 1  ':'  sarr[posn]  ", "; 145 150 } // for 146 sout  nl ;151 sout  nl  nl; 147 152 } 148 153 } // main
Note: See TracChangeset
for help on using the changeset viewer.