theprogrammablemind 7.5.0-beta.0 → 7.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/digraph.js +24 -7
package/package.json
CHANGED
package/src/digraph.js
CHANGED
@@ -9,21 +9,38 @@ const toA = (edge) => {
|
|
9
9
|
class Digraph {
|
10
10
|
// edges maybe either [child, parent] or { child, parent }
|
11
11
|
constructor (edges = []) {
|
12
|
-
this.
|
12
|
+
// dont make a copy of edges. this is shared and that breaks stuff. TODO fix this
|
13
|
+
this._edges = edges
|
13
14
|
}
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
addEdges(edges) {
|
17
|
+
for (let edge of edges) {
|
18
|
+
this.addEdge(edge)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
addEdge(edge) {
|
23
|
+
edge = toA(edge)
|
24
|
+
this._edges.push(edge)
|
25
|
+
}
|
26
|
+
|
27
|
+
get edges() {
|
28
|
+
return this._edges
|
29
|
+
}
|
30
|
+
|
31
|
+
/*
|
32
|
+
set edges(edges) {
|
33
|
+
this._edges = edges.map( toA )
|
18
34
|
}
|
19
35
|
*/
|
36
|
+
|
20
37
|
acdcs (s, from, to) {
|
21
38
|
const todo = [s]
|
22
39
|
const seen = new Set([s])
|
23
40
|
const acdcs = new Set([])
|
24
41
|
while (todo.length > 0) {
|
25
42
|
const n = todo.pop()
|
26
|
-
this.
|
43
|
+
this._edges.forEach((e) => {
|
27
44
|
e = toA(e)
|
28
45
|
if (e[from] === n) {
|
29
46
|
acdcs.add(e[to])
|
@@ -84,12 +101,12 @@ class Digraph {
|
|
84
101
|
}
|
85
102
|
|
86
103
|
add (child, parent) {
|
87
|
-
this.
|
104
|
+
this._edges.push([child, parent])
|
88
105
|
}
|
89
106
|
|
90
107
|
addList (l) {
|
91
108
|
for (let i = 1; i < l.length; ++i) {
|
92
|
-
this.
|
109
|
+
this._edges.push([l[i - 1], l[i]])
|
93
110
|
}
|
94
111
|
}
|
95
112
|
|