Skip to content

Commit edb3798

Browse files
committed
addNewAlgorithm.js fixes
1 parent 88af211 commit edb3798

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

addNewAlgorithm.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
// standalone JS - needs Node.js installed; run with node <thisfile>
1+
// standalone JS - needs Node.js installed; run with
2+
// node <thisfile>
23
//
34
// Idea here is to have a program that helps with creation of a new AIA
45
// algorithm module. Reads in the algorithm name and an ID used internally
56
// in code, filenames, etc. Output unix commands to create all the extra files
67
// (currently copy the heapsort files; they will need to be edited for the
78
// new algorithm), plus some snippets of code and indications of where to
8-
// put them so we can just edit a bunch of files and mostly copy+paste.
9-
// XXX It would be nice to be able to say what files to copy (not Heapsort)
10-
// but filenames are not really consistent enough currently.
9+
// put them so we can mostly copy+paste.
10+
// XXX It would be nice to be able to say what algorithm to copy (not Heapsort)
11+
// and input algCat but filenames are not really consistent enough currently.
1112

1213
const readline = require('readline');
1314

@@ -22,7 +23,7 @@ const rl = readline.createInterface({
2223

2324
let algName;
2425
let algID;
25-
let algCat = 'Sort'; // XXX Best input this also?
26+
let algCat = 'Sort';
2627
console.log("What's the name of your new algorithm used in menus etc, eg 2-3-4 Tree? ");
2728

2829
rl.on('line', (line) => {
@@ -43,17 +44,21 @@ rl.on('close', () => {
4344
});
4445

4546
// let devBranch = "<development branch>"
46-
let devBranch = "2025_sem2"
47+
let devBranch = "2025_sem2" // XXX
4748

4849
let doIt = (algName, algID) => {
4950
console.log("");
5051
console.log("Guide to adding algorithm named " + algName + " with ID " + algID);
5152
console.log("(best save this in a file and keep track of your progress)");
53+
console.log("If you follow these steps exactly (recommended) your new algorithm");
54+
console.log("will initially be a copy of Heapsort (you can then edit it as desired).");
55+
console.log("It will not appear in algorithm menus but can be accessed via the URL.");
56+
console.log("<base URL>/alg=" + algID + "&mode=sort");
5257
console.log("");
5358
console.log("Execute the following commands from the AIA repository directory:");
5459
console.log("");
5560
console.log("git switch " + devBranch + "; git pull");
56-
console.log("git switch +c add_" + algID);
61+
console.log("git switch -c add_" + algID);
5762
console.log("");
5863
console.log("cp src/algorithms/controllers/heapSort.js src/algorithms/controllers/" + algID + ".js");
5964
console.log("git add src/algorithms/controllers/" + algID + ".js");
@@ -70,13 +75,13 @@ let doIt = (algName, algID) => {
7075
console.log("but best defer that until after you have added the new algorithm");
7176
console.log("");
7277
console.log("echo \"export { default as " + algID + "} from './" + algID + "'\" >> src/algorithms/controllers/index.js");
73-
console.log("echo \"export { default as " + algID + "} from './" + algID + "'\" >> src/algorithms/explanations/index.js");
74-
console.log("echo \"export { default as " + algID + "} from './" + algID + "'\" >> src/algorithms/extra-info/index.js");
78+
console.log("echo \"export { default as " + algID + "} from './" + algID + ".md'\" >> src/algorithms/explanations/index.js");
79+
console.log("echo \"export { default as " + algID + "} from './" + algID + ".md'\" >> src/algorithms/extra-info/index.js");
7580
console.log("echo \"export { default as " + algID + "} from './" + algID + "'\" >> src/algorithms/parameters/index.js");
7681
console.log("echo \"export { default as " + algID + "} from './" + algID
7782
+ "'\" >> src/algorithms/pseudocode/index.js");
7883
console.log("");
79-
console.log("Edit src/algorithms/index.js to add to the allalgs definition; something like:");
84+
console.log("Edit src/algorithms/index.js to add the following to the allalgs definition:");
8085
console.log(" '" + algID + "': {");
8186
console.log(" name: '" + algName + "',");
8287
console.log(" noDeploy: false,");
@@ -91,8 +96,9 @@ let doIt = (algName, algID) => {
9196
console.log(" controller: {");
9297
console.log(" sort: Controller." + algID + ",");
9398
console.log(" },");
99+
console.log(" },");
94100
// XXX ...
95-
console.log("XXX Above may change with changes to index generation code");
101+
console.log("Note: above may change when code for algorithm index generation is modified");
96102
console.log("");
97103
console.log("Make sure the system compiles and existing algorithms run OK.");
98104
console.log("This may require checking and re-working some of the steps above.");

src/algorithms/extra-info/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ export { default as BFSInfo } from './BFSInfo.md';
2323
export { default as DFSInfo } from './DFSInfo.md';
2424
export { default as DFSrecInfo } from './DFSrecInfo.md';
2525
export { default as HashingInfo } from './HashingInfo.md';
26-

src/algorithms/index.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,18 @@ const allalgs = {
143143
},
144144

145145
'msort_arr_bup': {
146-
name: 'Merge Sort (bottom up)', // for bottom up
146+
name: 'Merge Sort (bottom up)',
147147
noDeploy: false,
148-
category: 'Sort', // for bottom up
149-
explanation: Explanation.msort_arr_bup, // for bottom up, working yet
150-
param: <Param.msort_arr_bup />, // same as top down
151-
instructions: Instructions.msort_arr_bup, // for bottom up same as top down
152-
extraInfo: ExtraInfo.msort_arr_bup, // same as top down
148+
category: 'Sort',
149+
explanation: Explanation.msort_arr_bup,
150+
param: <Param.msort_arr_bup />,
151+
instructions: Instructions.msort_arr_bup,
152+
extraInfo: ExtraInfo.msort_arr_bup,
153153
pseudocode: {
154-
sort: Pseudocode.msort_arr_bup, // same as top down
154+
sort: Pseudocode.msort_arr_bup,
155155
},
156156
controller: {
157-
sort: Controller.msort_arr_bup,// same as top down
157+
sort: Controller.msort_arr_bup,
158158
},
159159
},
160160

@@ -458,11 +458,6 @@ const allalgs = {
458458
noDeploy: false,
459459
name: 'Horspool\'s',
460460
category: 'String Search',
461-
/*
462-
Todo:
463-
1. Add explanation and extra info markdown contents
464-
2. Implement controller (check bookmark)
465-
*/
466461
explanation: Explanation.HSSExp,
467462
param: <Param.HSSParam />,
468463
instructions: Instructions.HSSInstruction,

0 commit comments

Comments
 (0)