public static List<CoalescedTreeNode> CreateRootTree(out CoalescedTreeNode root)
 {
     root = new CoalescedTreeNode(AlwaysTrueCondition.Instance);
     List<CoalescedTreeNode> list = new List<CoalescedTreeNode>();
     list.Add(root);
     return list;
 }
Пример #2
0
 protected override void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List<CoalescedTreeNode> children)
 {
     List<Condition> conditions = new List<Condition>(_conditions);
     CoalescedTreeNode localParent = parent;
     while(conditions.Count > 0)
     {
         bool found = false;
         foreach(CoalescedTreeNode child in localParent.ConditionAxis)
         {
             if(conditions.Contains(child.Condition))
             {
                 conditions.Remove(child.Condition);
                 localParent = child;
                 found = true;
             }
         }
         if(!found)
         {
             CoalescedTreeNode node = new CoalescedTreeNode(conditions[conditions.Count - 1]);
             conditions.RemoveAt(conditions.Count - 1);
             localParent.ConditionAxis.Add(node);
             localParent = node;
         }
     }
     children.Add(localParent);
 }
Пример #3
0
        protected override void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List <CoalescedTreeNode> children)
        {
            List <Condition>  conditions  = new List <Condition>(_conditions);
            CoalescedTreeNode localParent = parent;

            while (conditions.Count > 0)
            {
                bool found = false;
                foreach (CoalescedTreeNode child in localParent.ConditionAxis)
                {
                    if (conditions.Contains(child.Condition))
                    {
                        conditions.Remove(child.Condition);
                        localParent = child;
                        found       = true;
                    }
                }
                if (!found)
                {
                    CoalescedTreeNode node = new CoalescedTreeNode(conditions[conditions.Count - 1]);
                    conditions.RemoveAt(conditions.Count - 1);
                    localParent.ConditionAxis.Add(node);
                    localParent = node;
                }
            }
            children.Add(localParent);
        }
Пример #4
0
        public List <CoalescedTreeNode> MergeToCoalescedTree()
        {
            List <CoalescedTreeNode> res      = new List <CoalescedTreeNode>();
            CoalescedTreeNode        sentinel = new CoalescedTreeNode(AlwaysTrueCondition.Instance);

            MergeToCoalescedTreeNode(sentinel, res);
            return(res);
        }
Пример #5
0
        public static List <CoalescedTreeNode> CreateRootTree(out CoalescedTreeNode root)
        {
            root = new CoalescedTreeNode(AlwaysTrueCondition.Instance);
            List <CoalescedTreeNode> list = new List <CoalescedTreeNode>();

            list.Add(root);
            return(list);
        }
Пример #6
0
        protected virtual void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List <CoalescedTreeNode> children)
        {
            CoalescedTreeNode child;

            if (!TryGetExistingNode(parent, this, out child))
            {
                child = new CoalescedTreeNode(this);
                parent.ConditionAxis.Add(child);
            }
            children.Add(child);
        }
Пример #7
0
 protected bool TryGetExistingNode(CoalescedTreeNode parent, Condition condition, out CoalescedTreeNode node)
 {
     foreach (CoalescedTreeNode child in parent.ConditionAxis)
     {
         if (Equals(child.Condition))
         {
             node = child;
             return(true);
         }
     }
     node = null;
     return(false);
 }
Пример #8
0
        public bool CouldMergeToCoalescedTree(CoalescedTreeNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Condition.Equals(AlwaysTrueCondition.Instance))
            {
                return(true);
            }
            return(CouldMergeToCoalescedTreeNode(node.Condition));
        }
Пример #9
0
 protected override void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List <CoalescedTreeNode> children)
 {
     foreach (Condition condition in _conditions)
     {
         CoalescedTreeNode child;
         if (!TryGetExistingNode(parent, condition, out child))
         {
             child = new CoalescedTreeNode(condition);
             parent.ConditionAxis.Add(child);
         }
         children.Add(child);
     }
 }
 protected override void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List <CoalescedTreeNode> children)
 {
     children.Add(parent);
 }
Пример #11
0
        public override void MergeToCoalescedTree(MathIdentifier patternId, List <CoalescedTreeNode> parents)
        {
            if (_children.Count == 0)
            {
                base.MergeToCoalescedTree(patternId, parents);
            }
            else
            {
                // Merge Conditions & Groups -> "node"-List
                List <CoalescedTreeNode> nodes = Condition.MergeToCoalescedTree(parents);
                MergeGroupToCoalescedTree(patternId, nodes);

                // children: find matching pattern or create one
                AlwaysTrueCondition atc = AlwaysTrueCondition.Instance;
                foreach (CoalescedTreeNode node in nodes)
                {
                    // check all patterns the current node already has
                    List <CoalescedChildPattern> nodePatterns = node.PatternAxis;
                    bool nodeMatch = false;
                    foreach (CoalescedChildPattern pattern in nodePatterns)
                    {
                        // check all nodes of the current pattern whether they match.
                        List <CoalescedTreeNode> patternChildren = pattern.ChildrenAxis;
                        if (patternChildren.Count != _children.Count)
                        {
                            continue;
                        }
                        bool patternMatch = true;
                        for (int i = 0; i < _children.Count; i++)
                        {
                            if (!_children[i].Condition.CouldMergeToCoalescedTree(patternChildren[i]))
                            {
                                patternMatch = false;
                                break;
                            }
                        }
                        if (patternMatch)
                        {
                            // we found a matching pattern. merge our tree pattern to this pattern.
                            nodeMatch = true;
                            for (int i = 0; i < _children.Count; i++)
                            {
                                List <CoalescedTreeNode> list = new List <CoalescedTreeNode>();
                                list.Add(patternChildren[i]);
                                _children[i].MergeToCoalescedTree(patternId, list);
                            }
                        }
                    }
                    if (!nodeMatch)
                    {
                        // we didn't find a matching pattern. build a new such pattern.
                        CoalescedChildPattern pattern = new CoalescedChildPattern();
                        for (int i = 0; i < _children.Count; i++)
                        {
                            CoalescedTreeNode parent = new CoalescedTreeNode(AlwaysTrueCondition.Instance);
                            pattern.AddChild(parent);
                            List <CoalescedTreeNode> list = new List <CoalescedTreeNode>();
                            list.Add(parent);
                            _children[i].MergeToCoalescedTree(patternId, list);
                        }
                        node.PatternAxis.Add(pattern);
                    }
                }
            }
        }
 public void AddChild(CoalescedTreeNode node)
 {
     _childAxis.Add(node);
 }
 protected override void MergeToCoalescedTreeNode(CoalescedTreeNode parent, List<CoalescedTreeNode> children)
 {
     children.Add(parent);
 }
 public void AddChild(CoalescedTreeNode node)
 {
     _childAxis.Add(node);
 }