1 | ;
|
2 | /**
|
3 | * @license
|
4 | * Copyright Google LLC All Rights Reserved.
|
5 | *
|
6 | * Use of this source code is governed by an MIT-style license that can be
|
7 | * found in the LICENSE file at https://angular.io/license
|
8 | */
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.PartiallyOrderedSet = exports.CircularDependencyFoundException = exports.DependencyNotFoundException = void 0;
|
11 | const exception_1 = require("../exception");
|
12 | class DependencyNotFoundException extends exception_1.BaseException {
|
13 | constructor() {
|
14 | super('One of the dependencies is not part of the set.');
|
15 | }
|
16 | }
|
17 | exports.DependencyNotFoundException = DependencyNotFoundException;
|
18 | class CircularDependencyFoundException extends exception_1.BaseException {
|
19 | constructor() {
|
20 | super('Circular dependencies found.');
|
21 | }
|
22 | }
|
23 | exports.CircularDependencyFoundException = CircularDependencyFoundException;
|
24 | class PartiallyOrderedSet {
|
25 | constructor() {
|
26 | this._items = new Map();
|
27 | }
|
28 | _checkCircularDependencies(item, deps) {
|
29 | if (deps.has(item)) {
|
30 | throw new CircularDependencyFoundException();
|
31 | }
|
32 | deps.forEach((dep) => this._checkCircularDependencies(item, this._items.get(dep) || new Set()));
|
33 | }
|
34 | clear() {
|
35 | this._items.clear();
|
36 | }
|
37 | has(item) {
|
38 | return this._items.has(item);
|
39 | }
|
40 | get size() {
|
41 | return this._items.size;
|
42 | }
|
43 | forEach(callbackfn, thisArg) {
|
44 | for (const x of this) {
|
45 | callbackfn.call(thisArg, x, x, this);
|
46 | }
|
47 | }
|
48 | /**
|
49 | * Returns an iterable of [v,v] pairs for every value `v` in the set.
|
50 | */
|
51 | *entries() {
|
52 | for (const item of this) {
|
53 | yield [item, item];
|
54 | }
|
55 | }
|
56 | /**
|
57 | * Despite its name, returns an iterable of the values in the set,
|
58 | */
|
59 | keys() {
|
60 | return this.values();
|
61 | }
|
62 | /**
|
63 | * Returns an iterable of values in the set.
|
64 | */
|
65 | values() {
|
66 | return this[Symbol.iterator]();
|
67 | }
|
68 | add(item, deps = new Set()) {
|
69 | if (Array.isArray(deps)) {
|
70 | deps = new Set(deps);
|
71 | }
|
72 | // Verify item is not already in the set.
|
73 | if (this._items.has(item)) {
|
74 | const itemDeps = this._items.get(item) || new Set();
|
75 | // If the dependency list is equal, just return, otherwise remove and keep going.
|
76 | let equal = true;
|
77 | for (const dep of deps) {
|
78 | if (!itemDeps.has(dep)) {
|
79 | equal = false;
|
80 | break;
|
81 | }
|
82 | }
|
83 | if (equal) {
|
84 | for (const dep of itemDeps) {
|
85 | if (!deps.has(dep)) {
|
86 | equal = false;
|
87 | break;
|
88 | }
|
89 | }
|
90 | }
|
91 | if (equal) {
|
92 | return this;
|
93 | }
|
94 | else {
|
95 | this._items.delete(item);
|
96 | }
|
97 | }
|
98 | // Verify all dependencies are part of the Set.
|
99 | for (const dep of deps) {
|
100 | if (!this._items.has(dep)) {
|
101 | throw new DependencyNotFoundException();
|
102 | }
|
103 | }
|
104 | // Verify there's no dependency cycle.
|
105 | this._checkCircularDependencies(item, deps);
|
106 | this._items.set(item, new Set(deps));
|
107 | return this;
|
108 | }
|
109 | delete(item) {
|
110 | if (!this._items.has(item)) {
|
111 | return false;
|
112 | }
|
113 | // Remove it from all dependencies if force == true.
|
114 | this._items.forEach((value) => value.delete(item));
|
115 | return this._items.delete(item);
|
116 | }
|
117 | *[Symbol.iterator]() {
|
118 | const copy = new Map(this._items);
|
119 | for (const [key, value] of copy.entries()) {
|
120 | copy.set(key, new Set(value));
|
121 | }
|
122 | while (copy.size > 0) {
|
123 | const run = [];
|
124 | // Take the first item without dependencies.
|
125 | for (const [item, deps] of copy.entries()) {
|
126 | if (deps.size == 0) {
|
127 | run.push(item);
|
128 | }
|
129 | }
|
130 | for (const item of run) {
|
131 | copy.forEach((s) => s.delete(item));
|
132 | copy.delete(item);
|
133 | yield item;
|
134 | }
|
135 | if (run.length == 0) {
|
136 | // uh oh...
|
137 | throw new CircularDependencyFoundException();
|
138 | }
|
139 | }
|
140 | }
|
141 | get [Symbol.toStringTag]() {
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QgcnVuOiBUW10gPSBbXTtcbiAgICAgIC8vIFRha2UgdGhlIGZpcnN0IGl0ZW0gd2l0aG91dCBkZXBlbmRlbmNpZXMuXG4gICAgICBmb3IgKGNvbnN0IFtpdGVtLCBkZXBzXSBvZiBjb3B5LmVudHJpZXMoKSkge1xuICAgICAgICBpZiAoZGVwcy5zaXplID09IDApIHtcbiAgICAgICAgICBydW4ucHVzaChpdGVtKTtcbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgcnVuKSB7XG4gICAgICAgIGNvcHkuZm9yRWFjaCgocykgPT4gcy5kZWxldGUoaXRlbSkpO1xuICAgICAgICBjb3B5LmRlbGV0ZShpdGVtKTtcbiAgICAgICAgeWllbGQgaXRlbTtcbiAgICAgIH1cblxuICAgICAgaWYgKHJ1bi5sZW5ndGggPT0gMCkge1xuICAgICAgICAvLyB1aCBvaC4uLlxuICAgICAgICB0aHJvdyBuZXcgQ2lyY3VsYXJEZXBlbmRlbmN5Rm91bmRFeGNlcHRpb24oKTtcbiAgICAgIH1cbiAgICB9XG4gIH1cblxuICBnZXQgW1N5bWJvbC50b1N0cmluZ1RhZ10oKTogJ1NldCcge1xuICAgIHJldHVybiAnU2V0JztcbiAgfVxufVxuIl19 |
\ | No newline at end of file |