Esempio n. 1
0
        /// <summary>
        /// Retrieves a state from the state graph starting at this node
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <returns></returns>
        public TransducerState <TInput, TOutput> SetStateOutput(TInput input, TOutput output)
        {
            if (InternalTransitionTable.ContainsKey(input))
            {
                var state = InternalTransitionTable[input];

                // Create a new state with all transitions of the previous state
                var newState = new TransducerState <TInput, TOutput>(output);
                foreach (var kv in state.InternalTransitionTable)
                {
                    newState.InternalTransitionTable[kv.Key] = kv.Value;
                }

                return(InternalTransitionTable[input] = newState);
            }
            else
            {
                return(InternalTransitionTable[input] = new TransducerState <TInput, TOutput>(output));
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Retrieves a state from the state graph with this node as a starting point
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public TransducerState <TInput, TOutput> GetState(TInput input) =>
 InternalTransitionTable.ContainsKey(input)
         ? InternalTransitionTable[input]
         : InternalTransitionTable[input] = new TransducerState <TInput, TOutput>();
Esempio n. 3
0
 /// <summary>
 /// Initializes a transducer with a terminal <see cref="InitialState" />
 /// </summary>
 /// <param name="output"></param>
 public Transducer(TOutput output)
 {
     InitialState = new TransducerState <TInput, TOutput>(output);
 }
Esempio n. 4
0
 private Transducer(bool isShallowCopy, Transducer <TInput, TOutput> transducer)
 {
     InitialState = isShallowCopy ? transducer.InitialState.ShallowCopy() : transducer.InitialState.DeepCopy();
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a transducer with a non-terminal <see cref="InitialState" />
 /// </summary>
 public Transducer()
 {
     InitialState = new TransducerState <TInput, TOutput>();
 }