public DataTree<T> GetPaths<T>(DataTree<T> tree, int depth, int dimVal){
DataTree<T> result = new DataTree<T>();
List<GH_Path> paths = tree.Paths.Where(x => x.Indices[depth] == dimVal).ToList();
if(!paths.Any()) Print("No match found");
else{
foreach(GH_Path path in paths) result.AddRange(tree.Branch(path), path);
}
return result;
}
Where T is the Type in question
Obviously you can eleborate more on that if the tree is BIG: for instance first check if there’s indeed Paths with Depth that match depth etc etc. But in most of real-life cases LINQ has OK performance.
As a challenge add a search Interval (for the dimVal).
I can see now how managing Paths´s properties is the way.
Thank you very much. I like LINQ for short and clear syntax. Interesting challenge BTW.
I´m using this variation to get count of branches within a depth 2 DataTree for a nested loop.
dataTree.Paths.Where(x => x.Length == 2).Select(x => x.Indices[1]).Distinct().Count();