Пример #1
0
        private void SearchLeafNode(NodeExpression currentLeafNode, IReadOnlyList <NodeExpression> allLeaves, List <NodeExpressionMatchPair> results)
        {
            currentLeafNode.Visit();

            NodeExpression match = null;

            for (int i = 0; i < allLeaves.Count; i++)
            {
                if (allLeaves[i].Equals(currentLeafNode) && !allLeaves[i].Visited)
                {
                    match = allLeaves[i];
                    break;
                }
            }

            if (match == null)
            {
                return;
            }

            match.Visit();

            while (match.Parent?.Equals(currentLeafNode?.Parent) == true)
            {
                if (match.Parent.Children.Count != currentLeafNode.Parent.Children.Count)
                {
                    break;
                }

                match.Visit();
                currentLeafNode.Visit();

                match           = match.Parent;
                currentLeafNode = currentLeafNode.Parent;
            }

            match.Visit();
            currentLeafNode.Visit();

            results.Add(new NodeExpressionMatchPair(match, currentLeafNode));
        }
Пример #2
0
        private NodeExpression NextLeafNode(bool goingUp, NodeExpression currentNode)
        {
            if (currentNode == null)
            {
                return(null);
            }

            if (currentNode.Children.Count == 0)
            {
                if (currentNode.Visited)
                {
                    return(NextLeafNode(true, currentNode.Parent));
                }

                return(currentNode);
            }

            currentNode.Visit(false);

            if (goingUp)
            {
                return(TryGoDown(currentNode));
            }

            for (int i = 0; i < currentNode.Children.Count; i++)
            {
                var child = currentNode.Children[i];

                if (!child.Visited)
                {
                    return(NextLeafNode(false, child));
                }
            }

            return(NextLeafNode(true, currentNode.Parent));
        }