private void CalculateSubtrees() { MyUnionFind uf = new MyUnionFind(GrowthSteps.Length); for (int i = 0; i < GrowthSteps.Length; ++i) { var next = GrowthSteps[i].NextStep; if (next != -1) { uf.Union(i, next); } } /** * To calculate lineages: * - Find the zero steps * - Calculate a subtree for each. * - There is at most one cycle per connected component * - We follow any node and determine the cycle. * - Wach sequential lineage ends where it meets the cycle, we store that index * */ // Lists of growth subtrees Dictionary <int, MyTuple <List <int>, GrowthSubtree> > growthLists = new Dictionary <int, MyTuple <List <int>, GrowthSubtree> >(); for (int i = 0; i < GrowthSteps.Length; ++i) { var representant = uf.Find(i); MyTuple <List <int>, GrowthSubtree> subtree; if (!growthLists.TryGetValue(representant, out subtree)) { subtree = new MyTuple <List <int>, GrowthSubtree>(new List <int>(), new GrowthSubtree()); growthLists.Add(representant, subtree); ; m_subtrees.Add(subtree.Item2); GrowthSteps[i].Subtree = subtree.Item2; } subtree.Item1.Add(i); GrowthSteps[i].Subtree = subtree.Item2; } m_componentIndex = new int[GrowthSteps.Length]; foreach (var subtree in growthLists.Values) { subtree.Item2.Init(this, subtree.Item1); } }
public MyUnionFindTests() { Uf = new MyUnionFind(SIZE); }