private NodeChildren <Node> FindDuplicates(Node node)
        {
            node.Children.Sort();
            var candidates = new NodeChildren <Node>();

            candidates.AddRange(node.Children[0].Children);
            candidates.Remove(node);

            var count = 0;

            // Pulls out candidates with different counts of children than the master
            while (candidates.Count != count)
            {
                if (node.Children.Count != candidates[count].Children.Count)
                {
                    candidates.RemoveAt(count);
                }
                else
                {
                    count++;
                }
            }

            // May want to change the List to a Hashset to be faster.
            // Finds identical sets.
            foreach (var childNode in node.Children)
            {
                count = 0;
                while (candidates.Count != count)
                {
                    if (!childNode.Children.Contains(candidates[count]))
                    {
                        candidates.RemoveAt(count);
                    }
                    else
                    {
                        count++;
                    }
                }
            }
            candidates.Add(node);
            return(candidates);
        }
예제 #2
0
 public void AddChild(SyntaxNode child) => children.Add(child);