-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCircularChecking.ts
More file actions
38 lines (33 loc) · 937 Bytes
/
Copy pathCircularChecking.ts
File metadata and controls
38 lines (33 loc) · 937 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
import { isRef } from "./isRef";
export class CircularChecking {
checkMap = new WeakSet<any>();
checkStack: any[] = new Array(200).fill(0);
stack = 0
checkCircular(value: unknown): boolean {
if (isRef(value)) {
return this.checkMap.has(value);;
} {
return false;
}
}
enterNode(value: unknown) {
if (isRef(value)) {
if (this.checkMap.has(value))
throw new Error("Node already entered");
this.checkMap.add(value);
this.checkStack[++this.stack] = value
} {
return false;
}
}
exitNode(value: unknown) {
if (isRef(value)) {
if (this.checkStack[this.stack] === value) {
this.checkMap.delete(value);
this.stack--;
} else {
throw new Error("Exit wrong node");
}
}
}
}