-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti-node.js
49 lines (39 loc) · 1.11 KB
/
multi-node.js
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
43
44
45
46
47
48
49
'use strict';
let counter = 0;
class MultiNode {
constructor(accepting) {
// this._transitions = new Map();
this._transitions = {};
this._accepting = accepting || [];
this._id = counter++;
}
getId() {
return this._id;
}
isAccepting() {
return this._accepting.length !== 0;
}
addTransition(symbol, node) {
let insert = {
target: node
};
// this._transitions.set(symbol, insert);
this._transitions[symbol] = insert;
}
getTransition(symbol) {
// return this._transitions.get(symbol);
return this._transitions[symbol];
}
hasTransition(symbol) {
// return this._transitions.has(symbol);
return !(this._transitions[symbol] === undefined);
// return symbol in this._transitions;
// return this._transitions.hasOwnProperty(symbol);
}
forEachTransition(func) {
Object.keys(this._transitions).forEach((transitionKey) => {
func(transitionKey, this._transitions[transitionKey]);
});
}
};
module.exports = MultiNode;