public void MatchJoinNode <T>(Action <JoinNode <T> > callback) where T : class { if (_alphaNodes.Count == 0) { return; } _alphaNodes[0].Select <T>(alpha => { if (_alphaNodes.Count == 1) { _configurator.MatchJoinNode(alpha, callback); return; } MemoryNode <T> left = alpha; for (int i = 1; i < _alphaNodes.Count; i++) { _alphaNodes[i].Select <T>(right => { _configurator.MatchJoinNode(left, right, join => { if (i + 1 < _alphaNodes.Count) { left = join; } else { callback(join); } }); }); } }); }
public bool MatchJoinNode <T>(Action <MemoryNode <T> > callback) where T : class { if (_alphaNodes.Count == 0) { return(false); } if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Tuple <,>)) { Type[] arguments = typeof(T).GetGenericArguments(); var tupleNode = (RuleNodeSelector)Activator.CreateInstance( typeof(TupleRuleNodeSelector <,>).MakeGenericType(arguments[0], arguments[1]), _configurator, this); return(tupleNode.Select(callback)); } var done = new HashSet <int>(); MemoryNode <T> left = null; for (int index = 0; index < _alphaNodes.Count; index++) { if (done.Contains(index)) { continue; } if (_alphaNodes[index].Select <T>(alpha => { done.Add(index); left = alpha; for (int i = index + 1; i < _alphaNodes.Count; i++) { if (done.Contains(i)) { continue; } _alphaNodes[i].Select <T>(right => { done.Add(i); _configurator.MatchJoinNode(left, right, join => { left = join; }); }); } })) { break; } } if (left != null) { if (left is AlphaNode <T> ) { _configurator.MatchJoinNode(left, join => { left = join; }); } callback(left); return(true); } return(false); }