@@ -175,19 +175,19 @@ export function run_msort() {
175
175
let A = nodes ;
176
176
let B = [ ...entire_num_array ] . fill ( undefined ) ;
177
177
let runlength = 1 ; // length of run to merge
178
- let runcount = 2 ; // number of runs merged
178
+ let runcount = 0 ; // number of runs merged
179
179
180
180
chunker . add ( 'Main' , ( vis , a , b , c_length , c_count ) => {
181
181
vis . array . set ( a , 'msort_arr_nat' ) ;
182
- // if (c_length === 1 ) {
183
- vis . array . setLargestValue ( maxValue ) ;
184
- //}
182
+ if ( runcount === 0 ) {
183
+ vis . array . setLargestValue ( maxValue ) ;
184
+ }
185
185
if ( isMergeCopyExpanded ( ) ) {
186
186
vis . arrayB . set ( b , 'msort_arr_nat' ) ;
187
187
vis . arrayB . setLargestValue ( maxValue ) ;
188
188
}
189
189
190
- } , [ A , B , size ] ) ;
190
+ } , [ A , B , size , runcount ] ) ;
191
191
192
192
/*chunker.add('runlength', (vis, c_rlength) => {
193
193
displayRunlength(vis, c_rlength, size);
@@ -218,12 +218,12 @@ export function run_msort() {
218
218
assignVarToA ( vis , 'left' , c_left , size ) ;
219
219
} , [ left ] ) ;
220
220
221
- while ( left <= size ) {
221
+ do {
222
222
223
223
let mid = left ;
224
224
225
225
chunker . add ( 'MergeAllWhile' , ( vis , c_left , c_mid , c_right ) => {
226
- highlight2Runlength ( vis , c_left , c_mid , c_right , colorA , colorB ) ;
226
+ // highlight2Runlength(vis, c_left, c_mid, c_right, colorA, colorB);
227
227
} , [ left , mid ] ) ;
228
228
229
229
chunker . add ( 'mid' , ( vis , c_mid , c_rlength ) => {
@@ -445,8 +445,11 @@ export function run_msort() {
445
445
} , [ A , B , left , right , runlength ] ) ;
446
446
}
447
447
let left2 = left ; // this is the old left before it was updated
448
-
448
+ //if (right + 1 <= size) {
449
449
left = right + 1 ;
450
+ //} else {
451
+ // left = 0;
452
+ //}
450
453
runcount = runcount + 1 ;
451
454
chunker . add ( 'runcount+' , ( vis , c_rlength ) => {
452
455
/*assignVarToA(vis, 'left', undefined, size);
@@ -466,9 +469,9 @@ export function run_msort() {
466
469
467
470
} , [ left2 , left , right ] ) ;
468
471
469
- }
472
+ } while ( left < size ) ;
470
473
471
- } while ( runcount <= 1 ) ;
474
+ } while ( runcount > 1 ) ;
472
475
473
476
chunker . add ( 'Done' , ( vis ) => {
474
477
for ( let i = 0 ; i < size ; i ++ ) {
0 commit comments