@@ -47,22 +47,23 @@ export function flatten<T>(xss: Array<Array<T>>): Array<T> {
47
47
for ( let xs of xss ) flat . push ( ...xs ) ;
48
48
return flat ;
49
49
}
50
+ /** Preorder walk of dependency tree, circular dependencies is not allowed. */
50
51
export function deepDependencies < T > ( node : T , links : Links < T > ) : Array < T > {
51
52
let dependencies : Array < T > = [ ...links ( node ) ] ;
52
53
if ( is . empty ( dependencies ) ) return [ ] ; //base:no-dependency
53
54
else return flatten ( dependencies . map ( eDep => deepDependencies ( eDep , links ) . concat ( eDep ) ) ) ;
54
55
}
55
56
export function flatDependencies < T > ( root : T , links : Links < T > ) : Array < T > {
56
- let bfsQueue : Array < T > = [ ...links ( root ) ] ;
57
+ let addWithDepTodo : Array < T > = [ ...links ( root ) ] ; //data:bfs-queue
57
58
let dependencySet : Set < T > = new Set ( ) ;
58
- while ( is . notEmpty ( bfsQueue ) ) {
59
- let someNode = bfsQueue . shift ( ) ;
59
+ while ( is . notEmpty ( addWithDepTodo ) ) {
60
+ let someNode = addWithDepTodo . shift ( ) ;
60
61
if ( dependencySet . has ( someNode ) ) {
61
- continue ; // skip cyclic deps like a-b
62
+ continue ; // skip circular deps like a-b
62
63
} else {
63
64
dependencySet . add ( someNode ) ;
64
65
let itsDepencencies = links ( someNode ) ;
65
- bfsQueue . push ( ...itsDepencencies ) ;
66
+ addWithDepTodo . push ( ...itsDepencencies ) ;
66
67
}
67
68
}
68
69
return [ ...dependencySet . values ( ) ] ;
0 commit comments