Пример #1
0
 public IEnumerable <int> IntoIter()
 {
     for (var i = Lower; i < Upper; i++)
     {
         if (Used.Contains(i))
         {
             continue;
         }
         yield return(i);
     }
 }
Пример #2
0
 private static void dfs(Node node)
 {
     Used.Add(node);
     foreach (LinkNode outLink in node.OutLinks)
     {
         if (!Used.Contains(outLink.NodeEnd))
         {
             dfs(outLink.NodeEnd);
         }
     }
 }
Пример #3
0
        /**
         * 对象入池
         **/
        public void ReturnObject <T>(T Instance) where T : IPoolable, new()
        {
            Type Prototype = typeof(T);

            if (ObjectDict.ContainsKey(Prototype))
            {
                Queue <Object> Objects;
                List <Object>  Used;
                bool           Result = ObjectDict.TryGetValue(Prototype, out Objects);
                if (Result)
                {
                    ObjectUsedRef.TryGetValue(Prototype, out Used);
                    int Capacity = 0;
                    CapacityDict.TryGetValue(Prototype, out Capacity);
                    if (Used.Contains(Instance))
                    {
                        //更新使用引用计数
                        int UsedCount = 0;
                        ObjectUsedDict.TryGetValue(Prototype, out UsedCount);
                        UsedCount--;
                        ObjectUsedDict[Prototype] = UsedCount;

                        //从使用队列删除,并且将对象加入未使用队列
                        Used.Remove(Instance);

                        if (Objects.Count >= Capacity)
                        {
                            //空闲对象到达阀值则将对象直接丢弃等待垃圾回收
                            ((IDisposable)Instance).Dispose();
                        }
                        else
                        {
                            ((IPoolable)Instance).Reset();
                            Objects.Enqueue(Instance);
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Texts"></param>
        /// <returns></returns>
        private string Expand(string Text, Dictionary <string, string> Locals = null, HashSet <string> Used = null)
        {
            if (Used == null)
            {
                Used = new HashSet <string>();
            }
            string Output = "";
            var    Tokens = new CTokenReader(new CTokenizer(Text, TokenizeSpaces: true).Tokenize());

            Tokens.MoveNextSpace();
            while (Tokens.HasMore)
            {
                bool Stringify = false;

                if (Locals != null && Tokens.Current.Raw == "##")
                {
                    Tokens.MoveNextSpace();
                }

                if (Tokens.Current.Raw == "#")
                {
                    Tokens.MoveNextSpace();
                    if (Tokens.Current.Type == CTokenType.Identifier)
                    {
                        Stringify = true;
                    }
                    else
                    {
                        Stringify = false;
                        Output   += "#";
                    }
                }

                if (Tokens.Current.Type == CTokenType.Identifier)
                {
                    var CurrentIdentifier = Tokens.Current.Raw;
                    var UpdatedIdentifier = ReplaceSimpleVariable(CurrentIdentifier);
                    if (UpdatedIdentifier != CurrentIdentifier)
                    {
                        Output += UpdatedIdentifier;
                        Tokens.MoveNextSpace();
                        continue;
                    }
                    switch (CurrentIdentifier)
                    {
                    case "__VA_ARGS__":
                        CurrentIdentifier = "...";
                        break;
                    }

                    if (Locals != null && Locals.ContainsKey(CurrentIdentifier))
                    {
                        CurrentIdentifier = Locals[CurrentIdentifier];
                        if (Stringify)
                        {
                            CurrentIdentifier = CToken.Stringify(CurrentIdentifier);
                        }
                        Output += CurrentIdentifier;
                        Tokens.MoveNextSpace();
                    }
                    else if (!Used.Contains(CurrentIdentifier) && Context.Macros.ContainsKey(CurrentIdentifier))
                    {
                        var Macro = Context.Macros[CurrentIdentifier];

                        // Constant
                        if (Macro is MacroConstant)
                        {
                            Output += Expand(Macro.Replacement, null, new HashSet <string>(Used.Concat(new[] { CurrentIdentifier })));
                            Tokens.MoveNextSpace();
                        }
                        // Function
                        else
                        {
                            Tokens.MoveNextNoSpace();
                            Tokens.ExpectCurrent("(");
                            var MacroFunction = Context.Macros[CurrentIdentifier] as MacroFunction;

                            if (MacroFunction == null)
                            {
                                throw (new Exception("Trying to call a non-function macro"));
                            }

                            //Console.WriteLine(":: {0} :: ", Text);

                            var Parameters = ParseParameterList(Tokens, JustIdentifiers: false);
                            for (int n = 0; n < Parameters.Length; n++)
                            {
                                //Console.WriteLine("  {0}", Parameters[n]);
                                Parameters[n] = Expand(Parameters[n], Locals, Used);
                                //Console.WriteLine("    -> {0}", Parameters[n]);
                            }
                            var Map = MapFunctionParameters(MacroFunction.Parameters, Parameters);

                            //foreach (var Item in Map) Console.WriteLine("{0} -> {1}", Item.Key, Item.Value);

                            Output += Expand(MacroFunction.Replacement, Map, new HashSet <string>(new[] { CurrentIdentifier }));
                        }
                    }
                    else
                    {
                        Output += CurrentIdentifier;
                        Tokens.MoveNextSpace();
                    }
                }
                else
                {
                    Output += Tokens.Current.Raw;
                    Tokens.MoveNextSpace();
                }
            }
            return(Output);
        }
        private void Check(int column)
        {
            from     = column;
            fromPile = FindTableau[from];
            if (fromPile.Count == 0)
            {
                // No cards.
                return;
            }

            // Configure the working tableau.
            WorkingTableau.Variation = Variation;

            // Find roots.
            Roots.Clear();
            int row = fromPile.Count;

            Roots.Add(row);
            while (row > 0)
            {
                int count = fromPile.GetRunUpAnySuit(row);
                row -= count;
                Roots.Add(row);
            }
            int runs = Roots.Count - 1;

            if (runs <= 1)
            {
                // Not at least two runs.
                return;
            }

            // Check first with no uncovering moves.
            best = -1;
            CheckOne(Move.Empty);

            Used.Clear();
            for (int i = 0; i < UncoveringMoves.Count; i++)
            {
                // Make sure the move doesn't interfere.
                Move move = UncoveringMoves[i];
                if (move.From == from || move.To == from)
                {
                    continue;
                }

                // Only need to try an uncovered card once.
                if (Used.Contains(move.From))
                {
                    continue;
                }
                Used.Add(move.From);

                // The uncovered card has to match a root to be useful.
                Card uncoveredCard = FindTableau[move.From][move.FromRow - 1];
                bool matchesRoot   = false;
                for (int j = 1; j < Roots.Count; j++)
                {
                    if (uncoveredCard.IsTargetFor(fromPile[Roots[j]]))
                    {
                        matchesRoot = true;
                        break;
                    }
                }
                if (!matchesRoot)
                {
                    continue;
                }

                // Try again to find a composite single pile move.
                move.ToRow = -1;
                CheckOne(move);
            }
        }