private SearchState BuildStartState()
 {
     SearchState result = new SearchState();
     m_allStates.Add(result);
     return result;
 }
        void EvolveState(SearchState pState)
        {
            Dictionary<char, SearchState> mapEvolvedStates = new Dictionary<char,SearchState>();
            MultiMap<char, string> mapCompletedPatterns = new MultiMap<char, string>();

            // move on each of the pattern strings we are currently following, incrementing the dotpos
            foreach (PatternState ps in pState.PatternStates)
            {
                if (ps.DotPos == ps.PatternString.Length)
                    continue;
                char cBase = (ps.PatternString)[ps.DotPos];
                if (m_target.CaseInsensitive)
                    cBase = Char.ToUpper(cBase);

                List<char> cList = RedlineMLSearch.GetCharToMatchSpecial(cBase);
                if (cList != null)
                {
                    foreach (char c in cList)
                    {
                        HandleCharEvolvingPattern(mapEvolvedStates, mapCompletedPatterns, ps, c);
                    }
                }
                else
                {
                    HandleCharEvolvingPattern(mapEvolvedStates, mapCompletedPatterns, ps, cBase);
                }
            }

            // add a new followed pattern for each of the root patterns (might start again here)
            foreach (string sPat in m_patterns)
            {
                Char cBase = sPat[0];
                if (m_target.CaseInsensitive)
                    cBase = Char.ToUpper(cBase);

                List<char> cList = RedlineMLSearch.GetCharToMatchSpecial(cBase);
                if (cList != null)
                {
                    foreach (char c in cList)
                    {
                        HandleCharStartingPattern(mapEvolvedStates, mapCompletedPatterns, sPat, c);
                    }
                }
                else
                {
                    HandleCharStartingPattern(mapEvolvedStates, mapCompletedPatterns, sPat, cBase);
                }
            }

            // for all characters we are interested in, set the transfers from this state, linking back into existing states if they exist;
            foreach (Char c in mapEvolvedStates.Keys)
            {
                var transfer = new StateTransfer();
                SearchState ss = mapEvolvedStates[c];
                transfer.destState = FindOrInsertState(ss);

                // tag the patterns we complete with this step, if any
                transfer.acceptedPatterns = mapCompletedPatterns[c];

                pState.SetTransfer(c, transfer);
            }
        }
        SearchState FindOrInsertState(SearchState thisState)
        {
            for (int i = 0; i < m_allStates.Count; i++)
            {
                if (m_allStates[i] == thisState)
                    return m_allStates[i];
            }

            m_allStates.Add(thisState);

            return thisState;
        }