AddressMatch.AddrSet.FindNodeInHashTable C# (CSharp) Method

FindNodeInHashTable() public method

Find node with specific name in HashTable
public FindNodeInHashTable ( string name ) : State
name string name of node
return State
        public State FindNodeInHashTable(string name)
        {
            State state = new State();
            if (AddrGraph.NodeTable[name] == null)
            {
                state.Name = name;
                state.MaxStateLEVEL = LEVEL.Uncertainty;
                state.MinStateLEVEL = LEVEL.Uncertainty;
                state.NodeCount = 0;
                state.NodeList = null;
                return state;
            }
            TableNode node = AddrGraph.NodeTable[name] as TableNode;
            LEVEL min = node.GNode.NodeLEVEL;
            LEVEL max = node.GNode.NodeLEVEL;
            state.NodeList.Add(node.GNode);
            int i = 1;
            while (node.Next != null)
            {
                min = min < node.Next.GNode.NodeLEVEL ? min : node.Next.GNode.NodeLEVEL;
                max = max > node.Next.GNode.NodeLEVEL ? max : node.Next.GNode.NodeLEVEL;
                state.NodeList.Add(node.Next.GNode);
                node = node.Next;
                i++;
            }
            state.Name = name;
            state.NodeCount = i;

            return state;
        }

Usage Example

Example #1
0
        /// <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);
        }