public MatchResult Match(String[] s)
{
MatchHelper.Assert(s.Count() == 0,
@" input string[]'s length is 0 ");
Stack<State> MatchStack = new Stack<State>();
MatchResult result = new MatchResult();
s.Reverse();
//Store the first Match
State firstState = new State();
ReaderWriterLockSlim rwlock = _addrset.GetRWlock();
rwlock.EnterReadLock();
for (int i = 0; i < s.Count();i++)
{
State correntState = _addrset.FindNodeInHashTable(s[i]);
if (i ==0)
{
firstState = correntState;
}
if (correntState.NodeCount == 0)
{
result.ResultState = MatchResultState.NOTFOUND;
goto RESULT;
}
//MatchStack.
if (MatchStack.Count > 0)
{
FilterState(correntState, MatchStack.Peek());
if (correntState.NodeCount == 0)
{
result.ResultState = MatchResultState.NOTMATCHED;
goto RESULT;
}
}
MatchStack.Push(correntState);
}
if (MatchStack.Count == 0)
{
result.ResultState = MatchResultState.NOTFOUND;
goto RESULT;
}
if (MatchStack.Peek().NodeCount > 1)
{
result.ResultState = MatchResultState.MULTIMATCHED;
goto RESULT;
}
List<GraphNode> resList;
State TopState = MatchStack.Pop();
do
{
State nextState = MatchStack.Pop();
resList =
_addrset.ForwardSearchNode(delegate(GraphNode node)
{
return node.Name == nextState.Name;
},
TopState.NodeList);
//if (resList.Count > 1)
//{
// result.ResultState = MatchResultState.MULTIMATCHED;
// return result;
//}
} while (MatchStack.Count > 0);
rwlock.ExitReadLock();
if (resList == null || resList.Count == 0)
{
result.ResultState = MatchResultState.NOTMATCHED;
goto RESULT;
}
if (resList.Count > 1)
{
result.ResultState = MatchResultState.MULTIMATCHED;
goto RESULT;
}
result.Result = resList.First();
result.ResultState = MatchResultState.SUCCESS;
RESULT:
rwlock.ExitReadLock();
return result;
}