@@ -7,30 +7,39 @@ var temp;
77for ( cycleStart = 0 ; cycleStart <= N - 2 ; cycleStart ++ ) {
88 item = D [ cycleStart ] ;
99 pos = cycleStart ;
10+ tracer . _select ( cycleStart ) ;
11+
1012 for ( i = cycleStart + 1 ; i <= N - 1 ; i ++ ) {
13+ tracer . _select ( i ) . _wait ( ) . _deselect ( i ) ;
1114 if ( D [ i ] < item ) {
1215 pos ++ ;
1316 }
1417 }
1518 if ( pos == cycleStart ) {
19+ tracer . _deselect ( cycleStart ) ;
1620 continue ;
1721 }
1822 while ( item == D [ pos ] ) {
1923 pos ++ ;
2024 }
25+
2126 temp = D [ pos ] ;
2227 D [ pos ] = item ;
2328 item = temp ;
2429
25- logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos ) ;
26-
27- tracer . _notify ( pos , D [ pos ] ) . _notify ( cycleStart , D [ cycleStart ] ) . _wait ( ) ;
28- tracer . _denotify ( pos ) . _denotify ( pos ) ;
29-
30+ if ( pos !== cycleStart ) {
31+ logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos + '; the next value to rewrite is ' + item ) ;
32+ } else {
33+ logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos ) ;
34+ }
35+ tracer . _select ( pos ) . _wait ( ) . _deselect ( pos ) ;
36+ tracer . _notify ( pos , D [ pos ] ) . _notify ( cycleStart , D [ cycleStart ] ) . _wait ( ) . _denotify ( pos ) . _denotify ( cycleStart ) ;
3037
3138 while ( pos != cycleStart ) {
3239 pos = cycleStart ;
40+
3341 for ( i = cycleStart + 1 ; i <= N - 1 ; i ++ ) {
42+ tracer . _select ( i ) . _wait ( ) . _deselect ( i ) ;
3443 if ( D [ i ] < item ) {
3544 pos ++ ;
3645 }
@@ -39,14 +48,18 @@ for( cycleStart=0; cycleStart<=N-2; cycleStart++ ){
3948 while ( item == D [ pos ] ) {
4049 pos ++ ;
4150 }
51+
4252 temp = D [ pos ] ;
4353 D [ pos ] = item ;
4454 item = temp ;
4555
46- logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos ) ;
47-
48- tracer . _notify ( pos , D [ pos ] ) . _notify ( cycleStart , D [ cycleStart ] ) . _wait ( ) ;
49- tracer . _denotify ( pos ) . _denotify ( pos ) ;
56+ if ( pos !== cycleStart ) {
57+ logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos + '; the next value to rewrite is ' + item ) ;
58+ } else {
59+ logger . _print ( 'Rewrite ' + D [ pos ] + ' to index ' + pos ) ;
60+ }
61+ tracer . _select ( pos ) . _wait ( ) . _deselect ( pos ) ;
62+ tracer . _notify ( pos , D [ pos ] ) . _notify ( cycleStart , D [ cycleStart ] ) . _wait ( ) . _denotify ( pos ) . _denotify ( cycleStart ) ;
5063
5164 writes ++ ;
5265 }
0 commit comments