-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOptionsFromBSTNode.js
More file actions
41 lines (32 loc) · 877 Bytes
/
OptionsFromBSTNode.js
File metadata and controls
41 lines (32 loc) · 877 Bytes
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
var BaseOptions = require("./BaseOptions.js");
var BSTTraverser = require("../Burst/BSTTraverser.js");
var ATNTraverser = require("../Burst/ATNTraverser.js");
var OptionsFromBSTNode = module.exports = function (trie)
{
this.trie = trie;
};
OptionsFromBSTNode.prototype = new BaseOptions();
OptionsFromBSTNode.prototype.getOptionsFor = function (term)
{
var results = this.trie.get(term);
var options = [];
this.produceOptions(results.node,options,results.prefix);
options.sort();
return options;
};
OptionsFromBSTNode.prototype.produceOptions = function(node,options,prefix)
{
if (node.getType() == "CON")
{
BSTTraverser.traverse(node.bst,addOption,prefix);
}
else if (node.getType() == "ATN")
{
ATNTraverser.traverse(node,addOption,prefix);
}
function addOption(item,itemPrefix)
{
var option = itemPrefix + item.value;
options.push(option);
}
}