Beispiel #1
0
        //Condense all straight line dependencies
        private void StraightLineCondensePass()
        {
            List <AssociativeNode> nodesWithAContingent = new List <AssociativeNode>();

            foreach (AssociativeNode node in tracker.AllNodes)
            {
                if (tracker.DirectContingents[node].Count == 1)
                {
                    nodesWithAContingent.Add(node);
                }
            }

            foreach (AssociativeNode startNode in nodesWithAContingent)
            {
                //We might have already removed this, if so, skip
                if (!tracker.AllNodes.Contains(startNode))
                {
                    continue;
                }

                AssociativeNode        walkerNode  = startNode;
                List <AssociativeNode> accNodeList = new List <AssociativeNode>();


                while (tracker.DirectDependents[walkerNode].Count < 2 &&
                       (tracker.DirectDependents[walkerNode].Count == 0 ||                              //Last node in the tree
                        tracker.DirectContingents[tracker.DirectDependents[walkerNode][0]].Count == 1)) //straight line node
                {
                    //Disabled for Mono
                    //Debug.Assert(tracker.DirectContingents[tracker.DirectDependents[walkerNode]] == 1);

                    accNodeList.Add(walkerNode);

                    if (tracker.DirectDependents[walkerNode].Count == 0)
                    {
                        break;
                    }

                    //Disabled for Mono
                    //Debug.Assert(tracker.DirectDependents[walkerNode].Count == 1);

                    walkerNode = tracker.DirectDependents[walkerNode][0];
                }

                if (accNodeList.Count > 1)
                {
                    //We have a straight line to merge
                    MergeNode newNode = new MergeNode();

                    foreach (AssociativeNode n in accNodeList)
                    {
                        newNode.MergedNodes.Add(n);
                        tracker.AllNodes.Remove(n);
                    }

                    //Register the new node
                    tracker.AddNode(newNode);

                    //Update the existing dependency nodes to target the new nodes
                    foreach (AssociativeNode n in tracker.DirectContingents[accNodeList[0]])
                    {
                        tracker.AddDirectDependent(n, accNodeList[0]);
                        tracker.AddDirectDependent(n, newNode);
                        tracker.AddDirectContingent(newNode, n);
                    }

                    foreach (AssociativeNode n in tracker.DirectDependents[accNodeList[accNodeList.Count - 1]])
                    {
                        tracker.AddDirectContingent(n, accNodeList[accNodeList.Count - 1]);
                        tracker.AddDirectContingent(n, newNode);
                        tracker.AddDirectDependent(newNode, n);
                    }

                    foreach (AssociativeNode n in accNodeList)
                    {
                        tracker.RemoveDirectDependents(n);
                        tracker.RemoveDirectContingents(n);
                    }
                }
            }
        }