Пример #1
0
        public virtual void DeleteEdge(EDGE e)
        {
            NODE vf   = e.From;
            NODE vt   = e.To;
            bool done = ForwardEdgeSpace.TryGetValue(vf, out List <EDGE> list);

            if (done)
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    if (list[i].From.Equals(vf) && list[i].To.Equals(vt))
                    {
                        list.RemoveAt(i);
                        break;
                    }
                }
            }
            done = ReverseEdgeSpace.TryGetValue(vf, out List <EDGE> listr);
            if (done)
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    if (list[i].From.Equals(vt) && list[i].To.Equals(vf))
                    {
                        list.RemoveAt(i);
                        break;
                    }
                }
            }
        }
Пример #2
0
        public String toDot()
        {
            StringBuilder buf = new StringBuilder();

            buf.AppendFormat("digraph {0} ", graphName);
            buf.Append("{\n");
            buf.Append("  ");
            foreach (String node in nodes)
            {             // print all nodes first
                buf.Append(node);
                buf.Append("; ");
            }
            buf.Append("\n");
            foreach (String src in edges.Keys)
            {
                IList <string> output;
                if (edges.TryGetValue(src, out output))
                {
                    foreach (String trg in output)
                    {
                        buf.Append("  ");
                        buf.Append(src);
                        buf.Append(" -> ");
                        buf.Append(trg);
                        buf.Append(";\n");
                    }
                }
            }
            buf.Append("}\n");
            return(buf.ToString());
        }
Пример #3
0
        public void TestTryGetValue()
        {
            var multi = new MultiMap <string, int> {
                { "coso", 1 }, { "coso", 2 }, { "coso", 3 }
            };

            var didIt = multi.TryGetValue("coso", out var result);

            Assert.IsTrue(result == 1);
            Assert.IsTrue(didIt);

            var didnt = multi.TryGetValue("cosa", out var result2);

            Assert.IsTrue(result2 == 0);
            Assert.IsFalse(didnt);
        }
Пример #4
0
            private ITestDriver CreateTestDriver()
            {
                var excludedTestFrameworkIds = new List <string>();

#if RESHARPER_60
                var unitTestManager   = UnitTestManager.GetInstance(provider.Solution);
                var unitTestProviders = unitTestManager.GetEnabledProviders();
#else
                var unitTestProviders = provider.UnitTestProvidersManager.GetEnabledProviders();
#endif
                foreach (var testProvider in unitTestProviders)
                {
                    IList <string> frameworkIds;
                    if (IncompatibleProviders.TryGetValue(testProvider.ID, out frameworkIds))
                    {
                        excludedTestFrameworkIds.AddRange(frameworkIds);
                    }
                }

                var testFrameworkSelector = new TestFrameworkSelector
                {
                    Filter       = testFrameworkHandle => !excludedTestFrameworkIds.Contains(testFrameworkHandle.Id),
                    FallbackMode = TestFrameworkFallbackMode.Approximate
                };
                return(testFrameworkManager.GetTestDriver(testFrameworkSelector, logger));
            }
Пример #5
0
        public StaticModel buildMeshes()
        {
            List <V3N3T2> verts = new List <V3N3T2>();
            List <ushort> index = new List <ushort>();

            StaticModel sm = new StaticModel();

            int indexCount  = 0;
            int indexOffset = indexCount;

            foreach (Material mat in myTris.Keys)
            {
                List <Tri> tris;
                myTris.TryGetValue(mat, out tris);

                //build the vertex list
                foreach (Tri t in tris)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        V3N3T2 v = new V3N3T2();
                        v.Position = myVerts[t.i[j]];
                        if (t.uv[j] != -1)
                        {
                            v.TexCoord = myUvs[t.uv[j]];
                        }
                        if (t.n[j] != -1)
                        {
                            v.Normal = myNorms[t.n[j]];
                        }

                        //check if this exact vertex is already in the list
                        if (!verts.Contains(v))
                        {
                            verts.Add(v);
                        }

                        index.Add((ushort)verts.IndexOf(v));
                        indexCount++;
                    }
                }

                Mesh m = new Mesh();
                m.primativeType = PrimitiveType.Triangles;
                m.indexBase     = indexOffset;
                m.indexCount    = indexCount;
                m.material      = mat;
                sm.myMeshes.Add(m);

                //update index base for next pass
                indexOffset += indexCount;
                indexCount   = 0;
            }

            sm.myVbo.setData(verts);
            sm.myIbo.setData(index);

            return(sm);
        }
Пример #6
0
    public void AddAdditional(GenDeploy deploy, int x, int y)
    {
        List <GenDeploy> list;

        if (!Additional.TryGetValue(x, y, out list))
        {
            list             = new List <GenDeploy>(1);
            Additional[x, y] = list;
        }
        list.Add(deploy);
    }
Пример #7
0
        public IList <IComponentDescriptor> FindComponentsByServiceId(string serviceId)
        {
            IList <ComponentDescriptor> components;

            if (componentsByServiceId.TryGetValue(serviceId, out components))
            {
                return(new ReadOnlyCollection <IComponentDescriptor>(GenericCollectionUtils.ConvertAllToArray(components, d => d)));
            }

            return(EmptyArray <IComponentDescriptor> .Instance);
        }
Пример #8
0
        public List <string> GetDependencies(string changer)
        {
            List <string> changeds;

            if (dependencies.TryGetValue(changer, out changeds))
            {
                return(changeds);
            }
            else
            {
                return(EMPTY);
            }
        }
Пример #9
0
        public EventManager.EventResult onMessage(Event e)
        {
            EventManager.EventResult ret = EventManager.EventResult.IGNORED;

            List <Behavior> interestedBehaviors;

            if (myMessageInterestMap.TryGetValue(e.name, out interestedBehaviors) == true)
            {
                foreach (Behavior b in interestedBehaviors)
                {
                    ret = b.onEvent(e);
                }
            }

            return(ret);
        }
Пример #10
0
    public Container2D <GridSpace> GeneratePrototypes(LevelLayout layout)
    {
        MultiMap <GridSpace> ret  = new MultiMap <GridSpace>();
        ThemeElementSpec     spec = new ThemeElementSpec()
        {
            GenGrid = layout.Grids,
            Random  = layout.Random,
            Grid    = ret
        };

        foreach (Value2D <GenSpace> gen in spec.GenGrid)
        {
            if (gen.val.Deploys == null)
            {
                HandleEmptyDeploy(gen.val, spec.Random);
            }
            GridSpace space;
            if (!ret.TryGetValue(gen, out space))
            {
                space = new GridSpace(gen.val.Type, gen.x, gen.y)
                {
                    Theme = gen.val.Theme
                };
                space.Deploys = new List <GridDeploy>(gen.val.Deploys.Count);
                ret[gen]      = space;
            }
            spec.GenSpace = gen.val;
            spec.Space    = space;
            spec.Theme    = gen.val.Theme;
            spec.Type     = gen.val.Type;
            spec.DeployX  = gen.x;
            spec.DeployY  = gen.y;
            List <GenDeploy> tmp = new List <GenDeploy>(gen.val.MainDeploys);
            foreach (GenDeploy genDeploy in tmp)
            {
                spec.GenDeploy = genDeploy;
                Deploy(spec);
            }
        }
        return(ret);
    }
Пример #11
0
 public virtual List <ISymbol> getSymbol(string name)
 {
     symbols.TryGetValue(name, out List <ISymbol> result);
     return(result);
 }
Пример #12
0
 public IList <IPrintedCard> this[DeckSection s] => sections.TryGetValue(s, out List <IPrintedCard> list) ? list : EmptySection;
Пример #13
0
        /// <summary>
        /// 인덱싱된 시퀀스에서 일치하는 키를 기준으로 두 시퀀스의 요소를 연관시킵니다. 지정한 IEqualityComparer{TKey}를 사용하여 키를 비교합니다.
        /// </summary>
        public static IEnumerable <TResult> Join <TOuter, TInner, TKey, TResult>(
            this IndexableCollection <TOuter> outer,
            IndexableCollection <TInner> inner,
            Expression <Func <TOuter, TKey> > outerKeySelector,
            Expression <Func <TInner, TKey> > innerKeySelector,
            Func <TOuter, TInner, TResult> resultSelector,
            IEqualityComparer <TKey> comparer)
        {
            outer.ShouldNotBeNull("outer");
            inner.ShouldNotBeNull("inner");
            outerKeySelector.ShouldNotBeNull("outerKeySelector");
            innerKeySelector.ShouldNotBeNull("innerKeySelector");
            resultSelector.ShouldNotBeNull("resultSelector");

            bool hasIndex = false;

            if (innerKeySelector.NodeType == ExpressionType.Lambda &&
                innerKeySelector.Body.NodeType == ExpressionType.MemberAccess &&
                outerKeySelector.NodeType == ExpressionType.Lambda &&
                outerKeySelector.Body.NodeType == ExpressionType.MemberAccess)
            {
                var memberExpressionInner = (MemberExpression)innerKeySelector.Body;
                var memberExpressionOuter = (MemberExpression)outerKeySelector.Body;
                var innerIndex            = new MultiMap <int, TInner>();
                var outerIndex            = new MultiMap <int, TOuter>();

                if (inner.PropertyHasIndex(memberExpressionInner.Member.Name) &&
                    outer.PropertyHasIndex(memberExpressionOuter.Member.Name))
                {
                    innerIndex = inner.GetIndexByProperty(memberExpressionInner.Member.Name);
                    outerIndex = outer.GetIndexByProperty(memberExpressionOuter.Member.Name);
                    hasIndex   = true;
                }

                if (hasIndex)
                {
                    foreach (int outerKey in outerIndex.Keys)
                    {
                        IList <TOuter> outerGroup = outerIndex[outerKey];
                        IList <TInner> innerGroup;
                        if (innerIndex.TryGetValue(outerKey, out innerGroup))
                        {
                            // join on the GROUPS based on key result
                            IEnumerable <TInner>  inners  = innerGroup.AsEnumerable();
                            IEnumerable <TOuter>  outers  = outerGroup.AsEnumerable();
                            IEnumerable <TResult> results = outers.Join(inners, outerKeySelector.Compile(),
                                                                        innerKeySelector.Compile(),
                                                                        resultSelector, comparer);
                            foreach (TResult resultItem in results)
                            {
                                yield return(resultItem);
                            }
                        }
                    }
                }
            }

            if (hasIndex == false)
            {
                if (IsDebugEnabled)
                {
                    log.Debug("Index가 없으므로 System.Linq.Enumerable.Join()을 수행합니다. ");
                }

                var inners  = inner.AsEnumerable();
                var outers  = outer.AsEnumerable();
                var results = outers.Join(inners, outerKeySelector.Compile(),
                                          innerKeySelector.Compile(),
                                          resultSelector, comparer);

                foreach (var resultItem in results)
                {
                    yield return(resultItem);
                }
            }
        }
Пример #14
0
        /** Walk each NFA configuration in this DFA state looking for a conflict
         *  where (s|i|ctx) and (s|j|ctx) exist, indicating that state s with
         *  context conflicting ctx predicts alts i and j.  Return an Integer set
         *  of the alternative numbers that conflict.  Two contexts conflict if
         *  they are equal or one is a stack suffix of the other or one is
         *  the empty context.
         *
         *  Use a hash table to record the lists of configs for each state
         *  as they are encountered.  We need only consider states for which
         *  there is more than one configuration.  The configurations' predicted
         *  alt must be different or must have different contexts to avoid a
         *  conflict.
         *
         *  Don't report conflicts for DFA states that have conflicting Tokens
         *  rule NFA states; they will be resolved in favor of the first rule.
         */
        protected virtual HashSet <int> GetConflictingAlts()
        {
            // TODO this is called multiple times: cache result?
            //[email protected]("getNondetAlts for DFA state "+stateNumber);
            HashSet <int> nondeterministicAlts = new HashSet <int>();

            // If only 1 NFA conf then no way it can be nondeterministic;
            // save the overhead.  There are many o-a->o NFA transitions
            // and so we save a hash map and iterator creation for each
            // state.
            int numConfigs = _nfaConfigurations.Count;

            if (numConfigs <= 1)
            {
                return(null);
            }

            // First get a list of configurations for each state.
            // Most of the time, each state will have one associated configuration.
            MultiMap <int, NFAConfiguration> stateToConfigListMap =
                new MultiMap <int, NFAConfiguration>();

            for (int i = 0; i < numConfigs; i++)
            {
                NFAConfiguration configuration = (NFAConfiguration)_nfaConfigurations[i];
                int stateI = configuration.State;
                stateToConfigListMap.Map(stateI, configuration);
            }
            // potential conflicts are states with > 1 configuration and diff alts
            ICollection <int> states  = stateToConfigListMap.Keys.ToArray();
            int numPotentialConflicts = 0;

            foreach (int stateI in states)
            {
                bool thisStateHasPotentialProblem = false;
                IList <NFAConfiguration> configsForState;
                stateToConfigListMap.TryGetValue(stateI, out configsForState);
                int alt = 0;
                int numConfigsForState = configsForState.Count;
                for (int i = 0; i < numConfigsForState && numConfigsForState > 1; i++)
                {
                    NFAConfiguration c = (NFAConfiguration)configsForState[i];
                    if (alt == 0)
                    {
                        alt = c.Alt;
                    }
                    else if (c.Alt != alt)
                    {
                        /*
                         * [email protected]("potential conflict in state "+stateI+
                         *                 " configs: "+configsForState);
                         */
                        // 11/28/2005: don't report closures that pinch back
                        // together in Tokens rule.  We want to silently resolve
                        // to the first token definition ala lex/flex by ignoring
                        // these conflicts.
                        // Also this ensures that lexers look for more and more
                        // characters (longest match) before resorting to predicates.
                        // TestSemanticPredicates.testLexerMatchesLongestThenTestPred()
                        // for example would terminate at state s1 and test predicate
                        // meaning input "ab" would test preds to decide what to
                        // do but it should match rule C w/o testing preds.
                        if (dfa.Nfa.Grammar.type != GrammarType.Lexer ||
                            !dfa.NFADecisionStartState.enclosingRule.Name.Equals(Grammar.ArtificialTokensRuleName))
                        {
                            numPotentialConflicts++;
                            thisStateHasPotentialProblem = true;
                        }
                    }
                }
                if (!thisStateHasPotentialProblem)
                {
                    // remove NFA state's configurations from
                    // further checking; no issues with it
                    // (can't remove as it's concurrent modification; set to null)
                    stateToConfigListMap[stateI] = null;
                }
            }

            // a fast check for potential issues; most states have none
            if (numPotentialConflicts == 0)
            {
                return(null);
            }

            // we have a potential problem, so now go through config lists again
            // looking for different alts (only states with potential issues
            // are left in the states set).  Now we will check context.
            // For example, the list of configs for NFA state 3 in some DFA
            // state might be:
            //   [3|2|[28 18 $], 3|1|[28 $], 3|1, 3|2]
            // I want to create a map from context to alts looking for overlap:
            //   [28 18 $] -> 2
            //   [28 $] -> 1
            //   [$] -> 1,2
            // Indeed a conflict exists as same state 3, same context [$], predicts
            // alts 1 and 2.
            // walk each state with potential conflicting configurations
            foreach (int stateI in states)
            {
                IList <NFAConfiguration> configsForState;
                stateToConfigListMap.TryGetValue(stateI, out configsForState);
                // compare each configuration pair s, t to ensure:
                // s.ctx different than t.ctx if s.alt != t.alt
                int numConfigsForState = 0;
                if (configsForState != null)
                {
                    numConfigsForState = configsForState.Count;
                }
                for (int i = 0; i < numConfigsForState; i++)
                {
                    NFAConfiguration s = configsForState[i];
                    for (int j = i + 1; j < numConfigsForState; j++)
                    {
                        NFAConfiguration t = configsForState[j];
                        // conflicts means s.ctx==t.ctx or s.ctx is a stack
                        // suffix of t.ctx or vice versa (if alts differ).
                        // Also a conflict if s.ctx or t.ctx is empty
                        if (s.Alt != t.Alt && s.Context.ConflictsWith(t.Context))
                        {
                            nondeterministicAlts.Add(s.Alt);
                            nondeterministicAlts.Add(t.Alt);
                        }
                    }
                }
            }

            if (nondeterministicAlts.Count == 0)
            {
                return(null);
            }
            return(nondeterministicAlts);
        }
Пример #15
0
        /** Walk each NFA configuration in this DFA state looking for a conflict
         *  where (s|i|ctx) and (s|j|ctx) exist, indicating that state s with
         *  context conflicting ctx predicts alts i and j.  Return an Integer set
         *  of the alternative numbers that conflict.  Two contexts conflict if
         *  they are equal or one is a stack suffix of the other or one is
         *  the empty context.
         *
         *  Use a hash table to record the lists of configs for each state
         *  as they are encountered.  We need only consider states for which
         *  there is more than one configuration.  The configurations' predicted
         *  alt must be different or must have different contexts to avoid a
         *  conflict.
         *
         *  Don't report conflicts for DFA states that have conflicting Tokens
         *  rule NFA states; they will be resolved in favor of the first rule.
         */
        protected virtual HashSet<int> GetConflictingAlts()
        {
            // TODO this is called multiple times: cache result?
            //[email protected]("getNondetAlts for DFA state "+stateNumber);
            HashSet<int> nondeterministicAlts = new HashSet<int>();

            // If only 1 NFA conf then no way it can be nondeterministic;
            // save the overhead.  There are many o-a->o NFA transitions
            // and so we save a hash map and iterator creation for each
            // state.
            int numConfigs = _nfaConfigurations.Count;
            if ( numConfigs <= 1 )
            {
                return null;
            }

            // First get a list of configurations for each state.
            // Most of the time, each state will have one associated configuration.
            MultiMap<int, NFAConfiguration> stateToConfigListMap =
                new MultiMap<int, NFAConfiguration>();
            for ( int i = 0; i < numConfigs; i++ )
            {
                NFAConfiguration configuration = (NFAConfiguration)_nfaConfigurations[i];
                int stateI = configuration.State;
                stateToConfigListMap.Map( stateI, configuration );
            }
            // potential conflicts are states with > 1 configuration and diff alts
            ICollection<int> states = stateToConfigListMap.Keys.ToArray();
            int numPotentialConflicts = 0;
            foreach ( int stateI in states )
            {
                bool thisStateHasPotentialProblem = false;
                IList<NFAConfiguration> configsForState;
                stateToConfigListMap.TryGetValue(stateI, out configsForState);
                int alt = 0;
                int numConfigsForState = configsForState.Count;
                for ( int i = 0; i < numConfigsForState && numConfigsForState > 1; i++ )
                {
                    NFAConfiguration c = (NFAConfiguration)configsForState[i];
                    if ( alt == 0 )
                    {
                        alt = c.Alt;
                    }
                    else if ( c.Alt != alt )
                    {
                        /*
                        [email protected]("potential conflict in state "+stateI+
                                           " configs: "+configsForState);
                        */
                        // 11/28/2005: don't report closures that pinch back
                        // together in Tokens rule.  We want to silently resolve
                        // to the first token definition ala lex/flex by ignoring
                        // these conflicts.
                        // Also this ensures that lexers look for more and more
                        // characters (longest match) before resorting to predicates.
                        // TestSemanticPredicates.testLexerMatchesLongestThenTestPred()
                        // for example would terminate at state s1 and test predicate
                        // meaning input "ab" would test preds to decide what to
                        // do but it should match rule C w/o testing preds.
                        if ( dfa.Nfa.Grammar.type != GrammarType.Lexer ||
                             !dfa.NFADecisionStartState.enclosingRule.Name.Equals( Grammar.ArtificialTokensRuleName ) )
                        {
                            numPotentialConflicts++;
                            thisStateHasPotentialProblem = true;
                        }
                    }
                }
                if ( !thisStateHasPotentialProblem )
                {
                    // remove NFA state's configurations from
                    // further checking; no issues with it
                    // (can't remove as it's concurrent modification; set to null)
                    stateToConfigListMap[stateI] = null;
                }
            }

            // a fast check for potential issues; most states have none
            if ( numPotentialConflicts == 0 )
            {
                return null;
            }

            // we have a potential problem, so now go through config lists again
            // looking for different alts (only states with potential issues
            // are left in the states set).  Now we will check context.
            // For example, the list of configs for NFA state 3 in some DFA
            // state might be:
            //   [3|2|[28 18 $], 3|1|[28 $], 3|1, 3|2]
            // I want to create a map from context to alts looking for overlap:
            //   [28 18 $] -> 2
            //   [28 $] -> 1
            //   [$] -> 1,2
            // Indeed a conflict exists as same state 3, same context [$], predicts
            // alts 1 and 2.
            // walk each state with potential conflicting configurations
            foreach ( int stateI in states )
            {
                IList<NFAConfiguration> configsForState;
                stateToConfigListMap.TryGetValue(stateI, out configsForState);
                // compare each configuration pair s, t to ensure:
                // s.ctx different than t.ctx if s.alt != t.alt
                int numConfigsForState = 0;
                if ( configsForState != null )
                {
                    numConfigsForState = configsForState.Count;
                }
                for ( int i = 0; i < numConfigsForState; i++ )
                {
                    NFAConfiguration s = configsForState[i];
                    for ( int j = i + 1; j < numConfigsForState; j++ )
                    {
                        NFAConfiguration t = configsForState[j];
                        // conflicts means s.ctx==t.ctx or s.ctx is a stack
                        // suffix of t.ctx or vice versa (if alts differ).
                        // Also a conflict if s.ctx or t.ctx is empty
                        if ( s.Alt != t.Alt && s.Context.ConflictsWith( t.Context ) )
                        {
                            nondeterministicAlts.Add( s.Alt );
                            nondeterministicAlts.Add( t.Alt );
                        }
                    }
                }
            }

            if ( nondeterministicAlts.Count == 0 )
            {
                return null;
            }
            return nondeterministicAlts;
        }
Пример #16
0
 public ICardEdition GetEarliestEditionOfCard(string name)
 {
     return(CardPrintingsByName.TryGetValue(name, out List <ICardEdition> list) ? list.First() : null);
 }