public static void PrintResult(MatchResult result) { if (result == null) { Console.WriteLine("未初始化"); return; } Console.WriteLine("==DEBUG==Print MatchResult======="); Console.WriteLine("==result's state is " + TranslateState(result.ResultState)); Console.WriteLine("==matched node's name is " + result.Result.Name); Console.WriteLine("==matched node's id is " + result.Result.ID); Console.WriteLine("==matched node's LEVEL is " + result.Result.NodeLEVEL); }
/// <summary> /// Backward Match /// </summary> /// <param name="s">address string[]</param> /// <returns>result</returns> 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); }
/// <summary> /// Backward Match /// </summary> /// <param name="s">address string[]</param> /// <returns>result</returns> 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; }