public void Traverse(IEnumerable <TDependency> dependencies, ItemMatch pathAnchor, bool pathAnchorIsCountMatch, AbstractPathMatch <TDependency, TItem>[] expectedPathMatches) { Dictionary <TItem, TDependency[]> incidentDependencies = _backwards ? AbstractItem <TItem> .CollectIncomingDependenciesMap(dependencies) : AbstractItem <TItem> .CollectOutgoingDependenciesMap(dependencies); _seenInnerPathStarts.Clear(); Paths.Clear(); Counts.Clear(); _onPath.Clear(); TItem[] uniqueStartItems = (pathAnchor == null ? incidentDependencies.Keys : incidentDependencies.Keys.Where(i => pathAnchor.Matches(i).Success)).ToArray(); AbstractPathMatch <TDependency, TItem> endMatch; AbstractPathMatch <TDependency, TItem>[] innerMatches; int n = expectedPathMatches.Length; if (n == 0) { endMatch = null; innerMatches = expectedPathMatches; } else { endMatch = expectedPathMatches[n - 1]; innerMatches = expectedPathMatches.Take(n - 1).ToArray(); } foreach (var item in uniqueStartItems.OrderBy(i => i.Name)) { if (_seenInnerPathStarts.Add(item)) { List <PathNode <TItem, TDependency> > up = Traverse(root: item, incidentDependencies: incidentDependencies, expectedInnerPathMatches: innerMatches, endMatch: endMatch, down: new DownInfo(pathAnchorIsCountMatch ? item : null)); if (up != null) { Paths.Add(item, up); } } } }