locked
Recursive Efficiency! RRS feed

  • Question

  • User439975351 posted

    Hi all,

    I'm trying to speed up a hierarchical tree builder with LINQ, this is what I have but it takes ages for trees that are thousands deep! Any tip on speeding this up at all?

    void TreeBuilder(IEnumerable<Tree> data, int? id = null)
                {
                    var items = data.Where(d => d.parentId == id).OrderBy(o => o.id);
                    if (items.Any())
                    {
                        foreach (var item in items)
                        {
                            teamList.Add(Tuple.Create(item.id, Convert.ToInt32(item.parentId)));
                            TreeBuilder(data, item.id);
                        } 
                    }
                }

    Friday, September 29, 2017 11:24 AM

All replies