Ejemplo n.º 1
0
        public static TAdapter Adapt(TDFAState rootState, ref Dictionary <TDFAState, TAdapter> quickLookup, object connectionContext = null)
        {
            List <TDFAState> inputSet = new List <TDFAState>();
            bool             connectRoot;

            DFAState <TCheck, TNFAState, TDFAState, TSourceElement> .FlatlineState(rootState, inputSet);

            if (connectRoot = !inputSet.Contains(rootState))
            {
                inputSet.Insert(0, rootState);
            }
            var resultSet = (from dfa in inputSet
                             let dfaContext = new TAdapterContext()
                                              let dfaAdapter = new TAdapter()
            {
                AssociatedContext = dfaContext, AssociatedState = dfa
            }
                             select new { Adapter = dfaAdapter, State = dfa }).ToDictionary(dfAdapter => dfAdapter.State, dfAdapter => dfAdapter.Adapter);

            foreach (var dfa in inputSet)
            {
                foreach (var transition in dfa.OutTransitions.Keys)
                {
                    resultSet[dfa].OutgoingTransitions.Add(transition, resultSet[dfa.OutTransitions[transition]]);
                }
            }
            if (connectRoot)
            {
                resultSet[rootState].ConnectContext(connectionContext);
            }

            foreach (var dfa in inputSet)
            {
                foreach (var transition in dfa.OutTransitions.Keys)
                {
                    resultSet[dfa.OutTransitions[transition]].ConnectContext(connectionContext);
                }
            }
            quickLookup = resultSet;
            return(resultSet[rootState]);
        }
Ejemplo n.º 2
0
        public static TFlowGraphRoot CreateFlowGraph(TDFAState rootState)
        {
            var flatform = new List <TDFAState>();

            DFAState <TCheck, TNFAState, TDFAState, TSourceElement> .FlatlineState(rootState, flatform);

            if (!flatform.Contains(rootState))
            {
                flatform.Insert(0, rootState);
            }
            var            resultLookup = new Dictionary <TDFAState, TFlowGraphNode>();
            TFlowGraphRoot rootGraph    = new TFlowGraphRoot();

            foreach (var state in flatform)
            {
                TFlowGraphNode current = new TFlowGraphNode()
                {
                    Value = state
                };
                resultLookup.Add(state, (TFlowGraphNode)(object)(current));
                current.Root = rootGraph;
            }
            foreach (var state in flatform)
            {
                foreach (var check in state.OutTransitions.Keys)
                {
                    resultLookup[state].InternalCast()._Add(check, resultLookup[state.OutTransitions[check]]);
                }
            }
            var pluralTargets =
                (from n in resultLookup.Values
                 where n.PluralTarget || n.Value == rootState
                 select n).ToArray();
            var singletons =
                resultLookup.Values.Except(pluralTargets).ToArray();

            rootGraph.PluralTargets = new ControlledCollection <TFlowGraphNode>(pluralTargets);
            rootGraph.Singletons    = new ControlledCollection <TFlowGraphNode>(singletons);
            return(rootGraph);
        }