forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
42 lines (34 loc) · 1.09 KB
/
Copy pathcode.js
File metadata and controls
42 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
word += '$'; //special character
logger._print ('Appended \'$\' at the end of word as terminating (special) character. Beginning filling of suffixes');
function selectSuffix (word, i) {
var c = i;
while (i < word.length-1) {
wordTracer._select (i);
i++;
}
wordTracer._wait ();
while (c < word.length-1) {
wordTracer._deselect (c);
c++;
}
wordTracer._wait ();
}
(function createSA (sa, word) {
for (var i = 0; i < word.length; i++) {
sa [i] [1] = word.slice (i);
selectSuffix (word, i);
saTracer._notify (i, 1, sa [i] [1])._wait ();
saTracer._denotify (i, 1)._wait ();
}
}) (suffixArray, word);
logger._print ('Re-organizing Suffix Array in sorted order of suffixes using efficient sorting algorithm (O(N.log(N)))');
suffixArray.sort (function (a, b) {
logger._print ('The condition a [1] (' + a [1] + ') > b [1] (' + b [1] + ') is ' + (a [1] > b [1]));
return a [1] > b [1];
});
for (var i = 0; i < word.length; i++) {
saTracer._notify (i, 0, suffixArray [i] [0]);
saTracer._notify (i, 1, suffixArray [i] [1])._wait ();
saTracer._denotify (i, 0);
saTracer._denotify (i, 1);
}