Esempio n. 1
0
        // TODO: Stavet seznam setu.

        /// <summary>
        /// Adds the transition to the transition index if a transition equivalent to it is not there yet. If it is, it uses the already existing transition instead.
        /// </summary>
        /// <param name="transitionsByTargetState">The transition index (indexed by the target state).</param>
        /// <param name="key">The target state.</param>
        /// <param name="value">The new transition.</param>
        /// <param name="comparer">The comparer.</param>
        /// <returns>The new transition if it wasn't in the index yet, the existing tranwsition otherwise.</returns>
        private ITransition AddTransitionOrGetExisting(Dictionary <State, HashSet <ITransition> > transitionsByTargetState, State key, ITransition value, TransitionNonrecursiveEqualityComparer comparer)
        {
            if (!transitionsByTargetState.ContainsKey(key))
            {
                transitionsByTargetState.Add(key, new HashSet <ITransition>(comparer)
                {
                    value
                });
                return(value);
            }

            var set = transitionsByTargetState[key];

            if (set.Contains(value))
            {
                return(set.Single(p => comparer.Equals(p, value)));
            }

            set.Add(value);
            return(value);
        }