This PR uses DFS to traverse all package nodes and detect cyclic dependencies.
The reason for the improvement is, the ancestorMap in the original solution could be expensive as it will copy ancestorMap entries a lot of times. Also there is actually standard solution for detecting cycles using DFS.
This PR also did some refactoring and grouped some reused functions together :)
This PR uses DFS to traverse all package nodes and detect cyclic dependencies.
The reason for the improvement is, the
ancestorMap
in the original solution could be expensive as it will copy ancestorMap entries a lot of times. Also there is actually standard solution for detecting cycles using DFS.This PR also did some refactoring and grouped some reused functions together :)