private void AddUniqueAndNode(IForestNode firstChild, IForestNode secondChild) { var childCount = 1 + ((secondChild == null) ? 0 : 1); for (var c = 0; c < _children.Count; c++) { var andNode = _children[c]; if (andNode.Children.Count != childCount) { continue; } if (IsMatchedSubTree(firstChild, secondChild, andNode)) { return; } } // not found so return new and node var newAndNode = new AndForestNode(); newAndNode.AddChild(firstChild); if (childCount > 1) { newAndNode.AddChild(secondChild); } _children.Add(newAndNode); }
private void CloneUniqueChildSubTree(IInternalForestNode internalCompletedParseNode) { for (var a = 0; a < internalCompletedParseNode.Children.Count; a++) { var andNode = internalCompletedParseNode.Children[a]; var newAndNode = new AndForestNode(); for (var c = 0; c < andNode.Children.Count; c++) { var child = andNode.Children[c]; newAndNode.AddChild(child); } _children.Add(newAndNode); } }
private void AddUniqueAndNode(IForestNode first, IForestNode second = null) { var childCount = 1 + (second == null ? 0 : 1); foreach (var andNode in this.children) { if (andNode.Children.Count != childCount) { continue; } if (IsMatchedSubTree(andNode, first, second)) { return; } } // not found so add new and node var newAndNode = AndForestNode.Make(first, second); Debug.Assert(!(this is IntermediateForestNode) || this.children.Count == 0); this.children.Add(newAndNode); }
private void AddUniqueAndNode(IForestNode firstChild, IForestNode secondChild) { var childCount = 1 + ((secondChild == null) ? 0 : 1); for (var c = 0; c < _children.Count; c++) { var andNode = _children[c]; if (andNode.Children.Count != childCount) continue; if (IsMatchedSubTree(firstChild, secondChild, andNode)) return; } // not found so return new and node var newAndNode = new AndForestNode(); newAndNode.AddChild(firstChild); if (childCount > 1) newAndNode.AddChild(secondChild); _children.Add(newAndNode); }
private static bool IsMatchedSubTree(AndForestNode andNode, IForestNode first, IForestNode second) { return(first.Equals(andNode.First) && (second == null || second.Equals(andNode.Second))); }