Skip to content

Commit 7517899

Browse files
committed
feat: arrayB is viewed when expanded and bup highlight runlengths seperately
1 parent 83bc914 commit 7517899

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

src/algorithms/controllers/msort_arr_bup.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function run_msort() {
140140
let left_2 = c_left;
141141
let mid_2 = (c_rlength + c_left - 1);
142142
let right_2 = (Math.min(c_rlength * 2, size) - 1);
143-
highlight2Runlength(vis, left_2, mid_2, right_2, runAColor, runBColor);
143+
// highlight2Runlength(vis, left_2, mid_2, right_2, runAColor, runBColor);
144144
}, [A, left, runlength]);
145145

146146
while ((left + runlength) <= size) {
@@ -152,11 +152,11 @@ export function run_msort() {
152152
let right = Math.min(mid + runlength, (size - 1));
153153
chunker.add('mid', (vis, c_mid, c_left) => {
154154
assignVarToA(vis, 'mid', c_mid, size);
155-
//highlightFromTo(vis, c_left, c_mid, runAColor);
155+
highlightFromTo(vis, c_left, c_mid, runAColor);
156156
}, [mid, left]);
157157
chunker.add('right', (vis, c_right, c_mid) => {
158158
assignVarToA(vis, 'right', c_right, size);
159-
//highlightFromTo(vis, c_mid + 1, c_right, runBColor);
159+
highlightFromTo(vis, c_mid + 1, c_right, runBColor);
160160

161161
}, [right, mid]);
162162

@@ -293,7 +293,7 @@ export function run_msort() {
293293
// future color: should be runAColor & runBColor
294294
resetArrayA(vis, "bup", a, c_left, c_mid, c_right, c_rlength, runAColor, runCColor);
295295

296-
if (isMergeExpanded()) vis.arrayB.set(b, 'msort_arr_bup');
296+
if (isMergeCopyExpanded()) vis.arrayB.set(b, 'msort_arr_bup');
297297
assignVarToA(vis, 'ap2', c_ap2, size);
298298
assignVarToA(vis, 'max2', c_max2, size);
299299

@@ -312,9 +312,12 @@ export function run_msort() {
312312
vis.array.set(a, 'msort_arr_bup');
313313
set_simple_stack(vis.array, [`runlength = ${c_rlength}`]);
314314

315-
if (isMergeExpanded()) vis.arrayB.set(b, 'msort_arr_bup');
315+
if (isMergeCopyExpanded()) {
316+
vis.arrayB.set(b, 'msort_arr_bup');
317+
}
316318

317319
// highlight all sorted elements green
320+
318321
for (let i = c_left; i <= c_right; i++) highlight(vis, i, sortColor);
319322

320323
assignVarToA(vis, "left", c_left, size);
@@ -331,17 +334,6 @@ export function run_msort() {
331334
if (c_left < size) assignVarToA(vis, 'left', c_left, size);
332335
assignVarToA(vis, "right", c_right, size);
333336

334-
if ((c_left + c_rlength) < size) {
335-
let left_2 = c_left;
336-
let mid_2 = (c_rlength + c_left - 1);
337-
let right_2 = (Math.min((mid_2 + c_rlength + 1), size) - 1);
338-
highlight2Runlength(vis, left_2, mid_2, right_2, runAColor, runBColor);
339-
}
340-
if ((c_left + c_rlength) >= size) {
341-
highlightFromTo(vis, c_left, size - 1, runAColor);
342-
}
343-
344-
345337
}, [A, left, right, runlength]);
346338

347339
}

src/algorithms/controllers/msort_arr_nat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export function run_msort() {
337337
chunker.add('CopyRest2', (vis, a, b, c_ap2, c_max2, c_left, c_right, c_mid, c_rcount) => {
338338
// future color: should be runAColor & runBColor
339339
resetArrayA(vis, "nat", a, c_left, c_mid, c_right, c_rcount, runAColor, runCColor);
340-
if (isMergeExpanded()) vis.arrayB.set(b, 'msort_arr_nat');
340+
if (isMergeCopyExpanded()) vis.arrayB.set(b, 'msort_arr_nat');
341341
assignVarToA(vis, 'ap2', c_ap2, size);
342342
assignVarToA(vis, 'max2', c_max2, size);
343343
// highlight sorted elements green
@@ -351,7 +351,7 @@ export function run_msort() {
351351
}
352352
chunker.add('copyBA', (vis, a, b, c_left, c_right, c_rcount) => {
353353
vis.array.set(a, 'msort_arr_nat');
354-
if (isMergeExpanded()) vis.arrayB.set(b, 'msort_arr_nat');
354+
if (isMergeCopyExpanded()) vis.arrayB.set(b, 'msort_arr_nat');
355355
// highlight all sorted elements green
356356
for (let i = c_left; i <= c_right; i++) highlight(vis, i, sortColor);
357357
set_simple_stack(vis.array, [`runcount = ${c_rcount}`]);

src/algorithms/controllers/msort_shared.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function highlight(vis, index, color) {
2929

3030
// Same as highlight() but checks isMergeExpanded()/arrayB is displayed, otherwise does nothing
3131
export function highlightB(vis, index, color) {
32-
if (isMergeExpanded()) {
32+
if (isMergeCopyExpanded()) {
3333
if (color == 'red') {
3434
vis.arrayB.select(index);
3535
}

0 commit comments

Comments
 (0)