Skip to content

Commit 741b9a7

Browse files
committed
Add draft addNewAlgorithm.js
1 parent 4c0efba commit 741b9a7

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

addNewAlgorithm.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// standalone JS - needs Node.js installed; run with node <filename>
2+
//
3+
// Idea here is to have a program that helps with creation of a new AIA
4+
// algorithm module. Reads in the algorithm name and an ID used internally
5+
// in code, filenames, etc. Output unix commands to create all the extra files
6+
// (currently copy the heapsort files; they will need to be edited for the
7+
// 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+
10+
const readline = require('readline');
11+
12+
const rl = readline.createInterface({
13+
input: process.stdin,
14+
output: process.stdout,
15+
terminal: false
16+
});
17+
18+
// XXX there must be a better way to input a couple of things then call a
19+
// function with them as the arguments...
20+
21+
let algName;
22+
let algID;
23+
console.log("What's the name of your new algorithm used in menus etc, eg 2-3-4 Tree? ");
24+
25+
rl.on('line', (line) => {
26+
if (!algName) {
27+
algName = line.trim();
28+
console.log("What's the ID of your new algorithm used in code, eg tree_234? ");
29+
} else {
30+
algID = line.trim();
31+
doIt(algName, algID);
32+
process.exit(0);
33+
}
34+
});
35+
36+
rl.on('close', () => {
37+
console.log('Exiting...');
38+
process.exit(0);
39+
});
40+
41+
42+
let doIt = (algName, algID) => {
43+
console.log("");
44+
console.log("To add algorithm named " + algName + " with ID " + algID + ":");
45+
console.log("Execute the following commands from the AIA repository directory:");
46+
console.log("cp src/algorithms/controllers/heapSort.js src/algorithms/controllers/" + algID + ".js");
47+
console.log("git add src/algorithms/controllers/" + algID + ".js");
48+
console.log("cp src/algorithms/pseudocode/heapSort.js src/algorithms/pseudocode/" + algID + ".js");
49+
console.log("git add src/algorithms/pseudocode/" + algID + ".js");
50+
console.log("echo \"export { default as " + algID + "} from './" + algID + "'\" >> src/algorithms/controllers/index.js");
51+
// XXX + other index.js files, explanations, extra-info, edit instructions
52+
console.log("");
53+
console.log("Edit src/algorithms/index.js to add to the allalgs definition; something like:");
54+
console.log(" '" + algID + "': {");
55+
console.log(" name: '" + algName + "',");
56+
console.log(" category: 'Sort',");
57+
// XXX ...
58+
console.log("...},");
59+
// XXX ...
60+
}
61+
62+
/*
63+
let algName = "";
64+
let algID = "";
65+
rl.question("What's the name of your new algorithm (eg Union Find)? ", function(answer) {
66+
algName = answer;
67+
rl.question("What's the ID of your new algorithm (eg unionFind)? ", function(answer) {
68+
algID = answer;
69+
});
70+
process(algName, algID);
71+
rl.close();
72+
});
73+
74+
/*
75+
rl.question("What's the ID of your new algorithm (eg unionFind)? ", function(answer) {
76+
algID = answer;
77+
// console.log("Hello " + answer);
78+
rl.close();
79+
});
80+
*/
81+
82+
83+
84+

src/algorithms/explanations/HSExp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Heapsort is a general purpose in-place sorting algorithm that has
66
*<verbatim>O(n log n)</verbatim>* behavior in the worst case. It
7-
proceeds by first rearranging the array so it is a *heap* (which has some
7+
proceeds by first rearranging the input array so it is a *heap* (which has some
88
ordering maintained; see below) then converting the heap into a sorted
99
array.
1010

0 commit comments

Comments
 (0)