This repository was archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgraph.ts
More file actions
62 lines (54 loc) 路 1.67 KB
/
Copy pathgraph.ts
File metadata and controls
62 lines (54 loc) 路 1.67 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/** @internal */
export class Graph {
public dependants = new Map<string, string[]>();
public dependencies = new Map<string, string[]>();
public addDependency(dependant: string, dependency: string): void {
const dependencies = this.dependencies.get(dependant) || [];
if (dependencies.indexOf(dependency) < 0) {
dependencies.push(dependency);
this.dependencies.set(dependant, dependencies);
}
const dependants = this.dependants.get(dependency) || [];
if (dependants.indexOf(dependant) < 0) {
dependants.push(dependant);
this.dependants.set(dependency, dependants);
}
}
public removeDependant(dependency: string, dependant: string) {
const dependencies = this.dependencies.get(dependency);
if (dependencies) {
const index = dependencies.indexOf(dependant);
if (index >= 0) {
dependencies.splice(index, 1);
}
}
}
public removeDependency(dependant: string, dependency: string) {
const dependants = this.dependants.get(dependency);
if (dependants) {
const index = dependants.indexOf(dependant);
if (index >= 0) {
dependants.splice(index, 1);
}
}
}
public removeDependencies(dependant: string): string[] {
let dependencies = this.dependencies.get(dependant);
if (dependencies) {
dependencies = dependencies.slice();
dependencies.forEach(dependency => {
this.removeDependant(dependency, dependant);
});
this.dependencies.delete(dependant);
return dependencies;
} else {
return [];
}
}
public getDependantsOf(dependency: string): string[] {
return this.dependants.get(dependency) || [];
}
public getDependenciesOf(dependant: string): string[] {
return this.dependencies.get(dependant) || [];
}
}