@@ -7,30 +7,39 @@ var temp;
7
7
for ( cycleStart = 0 ; cycleStart <= N - 2 ; cycleStart ++ ) {
8
8
item = D [ cycleStart ] ;
9
9
pos = cycleStart ;
10
+ tracer . _select ( cycleStart ) ;
11
+
10
12
for ( i = cycleStart + 1 ; i <= N - 1 ; i ++ ) {
13
+ tracer . _select ( i ) . _wait ( ) . _deselect ( i ) ;
11
14
if ( D [ i ] < item ) {
12
15
pos ++ ;
13
16
}
14
17
}
15
18
if ( pos == cycleStart ) {
19
+ tracer . _deselect ( cycleStart ) ;
16
20
continue ;
17
21
}
18
22
while ( item == D [ pos ] ) {
19
23
pos ++ ;
20
24
}
25
+
21
26
temp = D [ pos ] ;
22
27
D [ pos ] = item ;
23
28
item = temp ;
24
29
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 ) ;
30
37
31
38
while ( pos != cycleStart ) {
32
39
pos = cycleStart ;
40
+
33
41
for ( i = cycleStart + 1 ; i <= N - 1 ; i ++ ) {
42
+ tracer . _select ( i ) . _wait ( ) . _deselect ( i ) ;
34
43
if ( D [ i ] < item ) {
35
44
pos ++ ;
36
45
}
@@ -39,14 +48,18 @@ for( cycleStart=0; cycleStart<=N-2; cycleStart++ ){
39
48
while ( item == D [ pos ] ) {
40
49
pos ++ ;
41
50
}
51
+
42
52
temp = D [ pos ] ;
43
53
D [ pos ] = item ;
44
54
item = temp ;
45
55
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 ) ;
50
63
51
64
writes ++ ;
52
65
}
0 commit comments