当前位置: 首页>>代码示例>>C#>>正文


C# SortedSet.Add方法代码示例

本文整理汇总了C#中SortedSet.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.Add方法的具体用法?C# SortedSet.Add怎么用?C# SortedSet.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedSet的用法示例。


在下文中一共展示了SortedSet.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

 public FlatXml Parse(XmlReader reader)
 {
     var nodes = new SortedSet<FlatXmlNode>();
     var position = 0;
     while (reader.Read())
     {
         switch (reader.NodeType)
         {
             case XmlNodeType.Element:
                 var element = new FlatXmlNode {Name = reader.Name, Depth = reader.Depth, Position = position};
                 nodes.Add(element);
                 if (reader.HasAttributes)
                 {
                     while (reader.MoveToNextAttribute())
                     {
                         position += 1;
                         var attribute = new FlatXmlNode {Name = reader.Name, Value = reader.Value, Position = position, Depth = reader.Depth};
                         nodes.Add(attribute);
                     }
                 }
                 break;
             case XmlNodeType.Text:
                 var t = new FlatXmlNode {Value = reader.Value, Depth = reader.Depth, Position = position};
                 nodes.Add(t);
                 break;
         }
         position += 1;
     }
     return new FlatXml(nodes);
 }
开发者ID:kalotay,项目名称:UnorderedXmlComparer,代码行数:30,代码来源:FlatXmlParser.cs

示例2: FindLongestPath

        private int FindLongestPath(int maxSalary, int startSalary)
        {
            IDictionary<int, int> longestPaths = new Dictionary<int, int>() { { startSalary, 1 }};
            SortedSet<int> salaries = new SortedSet<int>();
            salaries.Add(startSalary);

            while (salaries.Count != 0)
            {
                int salary = salaries.Min;
                int path = longestPaths[salary];

                foreach (int nextSalary in GetNextSalaries(maxSalary, salary))
                {
                    if (!salaries.Contains(nextSalary))
                    {
                        salaries.Add(nextSalary);
                        longestPaths.Add(nextSalary, path + 1);
                    }
                    else
                        if (longestPaths[nextSalary] < path + 1)
                            longestPaths[nextSalary] = path + 1;
                }

                salaries.Remove(salary);
            }

            return longestPaths.Values.Max();
        }
开发者ID:korzenikov,项目名称:Projects,代码行数:28,代码来源:IntegerPercentage.cs

示例3: Load

        /// <summary>
        /// FanIn
        /// </summary>
        public IEnumerable<Activity> Load(Feed feed)
        {
            var snapshot = new Dictionary<byte[], Queue<Activity>>(activityStreamStore.Count);
            foreach (var item in activityStreamStore)
            {
                snapshot.Add(item.Key, new Queue<Activity>(item.Value));
            }

            SortedSet<Activity> buffer = new SortedSet<Activity>(Activity.Comparer);
            var streams = feed.FeedStreams.ToList();
            var streamsCount = streams.Count;

            //  Init
            for (int streamIndexInsideSubsciption = 0; streamIndexInsideSubsciption < streamsCount; streamIndexInsideSubsciption++)
            {
                var streamId = streams[streamIndexInsideSubsciption];
                var activity = snapshot[streamId].Dequeue();
                buffer.Add(activity);
            }

            while (buffer.Count > 0)
            {
                Activity nextActivity = buffer.FirstOrDefault();
                buffer.Remove(nextActivity);
                var streamQueue = snapshot[nextActivity.StreamId];
                if (streamQueue.Count > 0)
                {
                    var candidate = snapshot[nextActivity.StreamId].Dequeue();
                    buffer.Add(candidate);
                }
                yield return nextActivity;
            }
        }
开发者ID:mentormate-kalinvenkov,项目名称:ActivityStreams,代码行数:36,代码来源:InMemoryActivityFeedRepository.cs

示例4: Main

        public static void Main()
        {
            var numberOfDigits = int.Parse(Console.ReadLine());

            var digits = new int[numberOfDigits];
            for (int i = 0; i < numberOfDigits; i++)
            {
                digits[i] = int.Parse(Console.ReadLine());
            }

            Array.Sort(digits);
            var allNumbers = new HashSet<int>();
            PermuteRep(digits, 0, digits.Length, allNumbers);

            var numbersWithMinNumberOfDivisors = new SortedSet<int>();
            var minCountOfDivisors = 10000;
            foreach (var number in allNumbers)
            {
                var divisorsCount = CalculateDivisors(number);
                if (divisorsCount < minCountOfDivisors)
                {
                    numbersWithMinNumberOfDivisors.Clear();
                    numbersWithMinNumberOfDivisors.Add(number);
                    minCountOfDivisors = divisorsCount;
                }
                else if (divisorsCount == minCountOfDivisors)
                {
                    numbersWithMinNumberOfDivisors.Add(number);
                }
            }

            Console.WriteLine(numbersWithMinNumberOfDivisors.Min);
        }
开发者ID:Novkirishki,项目名称:Data-Structures-and-Algorithms,代码行数:33,代码来源:Startup.cs

示例5: Main

 static void Main()
 {
     string[] input = Console.ReadLine().Split(new char []{' ',',','.','?','!'},StringSplitOptions.RemoveEmptyEntries);
     SortedSet<string> palindromes = new SortedSet<string>();
     for (int i = 0; i < input.Length; i++)
     {
         StringBuilder sb = new StringBuilder(input[i]);
         if (sb.Length == 1)
         {
             palindromes.Add(input[i]);
         }
         else
         {
             for (int j = 0; j < input[i].Length/2; j++)
             {
                 if (sb[j].Equals(sb[sb.Length - 1 - j]))
                 {
                     palindromes.Add(input[i]);
                 }
             }
         }
     }
     Console.Write(string.Join(", ",palindromes));
     Console.WriteLine();
 }
开发者ID:darimi27,项目名称:CSharp-Advanced,代码行数:25,代码来源:Palindromes.cs

示例6: find

        public int find(int[] array, int k)
        {
            if (array == null || array.Length == 0) return -1;

            SortedSet<int> queue = new SortedSet<int>();
            int maxItem = array[0];
            queue.Add(array[0]);

            foreach (int v in array)
            {
                if (queue.Count < k)
                    queue.Add(v);
                // can enqueue
                else if (v < queue.Max)
                {
                    queue.Remove(queue.Max);
                    queue.Add(v);
                }
            }

            int res = -1;
            foreach (var v in queue) {
                if (--k == 0) {
                    res = v;
                    break;
                }
            }

            return res;
        }
开发者ID:effectivewang,项目名称:onetake,代码行数:30,代码来源:KSmallestFinder.cs

示例7: Main

        static void Main(string[] args)
        {
            primes = new SortedSet<int>();
            not_primes = new SortedSet<int>();

            primes.Add(2);
            primes.Add(3);
            primes.Add(5);
            primes.Add(7);
            not_primes.Add(9);

            maxNumPrimes = 0;

            foreach(int a in Enumerable.Range(0, 1000))
            {
                foreach(int b in Enumerable.Range(0, 1000))
                {
                    TestQuadratic(a, b);
                    TestQuadratic(-a, b);
                    TestQuadratic(a, -b);
                    TestQuadratic(-a, -b);

                }
            }

            Console.WriteLine(maxNumPrimes);
            Console.WriteLine(maxA * maxB);
            Console.ReadLine();
        }
开发者ID:jeremygibbons,项目名称:Euler27,代码行数:29,代码来源:Program.cs

示例8: Main

    static void Main()
    {
        string text = Console.ReadLine();
        char[] splitters = { ' ', '.', ',', '!', '?' };
        string[] word = text.Split(splitters, StringSplitOptions.RemoveEmptyEntries);
        SortedSet<string> palyndromes = new SortedSet<string>();

        for (int i = 0; i < word.Length; i++)
        {
            string wordToCheck = word[i];
            int len = wordToCheck.Length;
            int halflen = len / 2;
            if (len == 1)
            {
                palyndromes.Add(wordToCheck);
            }
            else
            {
                string firstpart = wordToCheck.Substring(0, halflen);
                char[] temp = wordToCheck.Substring(len - halflen).ToCharArray();
                Array.Reverse(temp);
                string secondpart = new string(temp);

                if (firstpart == secondpart)
                {
                    palyndromes.Add(wordToCheck);
                }
            }
        }
        Console.WriteLine(String.Join(", ", palyndromes));
    }
开发者ID:desi4ok,项目名称:AdvancedCSharp,代码行数:31,代码来源:Palindromes.cs

示例9: Generate

		internal GetGeneratedEventsResults Generate(Type baseType, SortedSet<string> namespaces,
			NameGenerator generator, MethodInformationBuilder builder)
		{
			var requiresObsoleteSuppression = false;
         var generatedEvents = new List<string>();

			foreach (var @event in baseType.GetMockableEvents(generator))
			{
				var eventHandlerType = @event.EventHandlerType;
				namespaces.Add(eventHandlerType.Namespace);

				var eventMethod = @event.AddMethod;

				var methodInformation = builder.Build(new MockableResult<MethodInfo>(
					eventMethod, RequiresExplicitInterfaceImplementation.No));
				var @override = methodInformation.DescriptionWithOverride.Contains("override") ? "override " : string.Empty;

				if (eventMethod.IsPublic)
				{
					if (eventHandlerType.IsGenericType)
					{
						var eventGenericType = eventHandlerType.GetGenericArguments()[0];
						generatedEvents.Add(EventTemplates.GetEvent(@override,
							$"EventHandler<{eventGenericType.GetSafeName()}>", @event.Name));
						namespaces.Add(eventGenericType.Namespace);
					}
					else
					{
						generatedEvents.Add(EventTemplates.GetEvent(@override,
							eventHandlerType.GetSafeName(), @event.Name));
					}

					requiresObsoleteSuppression |= @event.GetCustomAttribute<ObsoleteAttribute>() != null;
				}
				else if (!eventMethod.IsPrivate && eventMethod.IsAbstract)
				{
					var visibility = CodeTemplates.GetVisibility(eventMethod.IsFamily, eventMethod.IsFamilyOrAssembly);

					if (eventHandlerType.IsGenericType)
					{
						var eventGenericType = eventHandlerType.GetGenericArguments()[0];
						generatedEvents.Add(EventTemplates.GetNonPublicEvent(visibility,
							$"EventHandler<{eventGenericType.GetSafeName()}>", @event.Name));
						namespaces.Add(eventGenericType.Namespace);
					}
					else
					{
						generatedEvents.Add(EventTemplates.GetNonPublicEvent(visibility,
							eventHandlerType.GetSafeName(), @event.Name));
					}

					requiresObsoleteSuppression |= @event.GetCustomAttribute<ObsoleteAttribute>() != null;
				}
			}

			return new GetGeneratedEventsResults(generatedEvents.AsReadOnly(), requiresObsoleteSuppression);
      }
开发者ID:JamesBender,项目名称:Rocks,代码行数:57,代码来源:EventsGenerator.cs

示例10: GeneratePagerNormalItems

		/// <summary>
		///     Core method for generating normal pager items according to the page information.
		/// </summary>
		/// <param name="currentPage">The current page number.</param>
		/// <param name="totalPage">The count of total pages.</param>
		/// <param name="expandForCurrentPage">How many pages should be expanded for current page.</param>
		/// <param name="expandForEnding">How many pages should be expanded for ending.</param>
		/// <returns></returns>
		private static IEnumerable<PagerItem> GeneratePagerNormalItems(int currentPage, int totalPage, int expandForCurrentPage,
			int expandForEnding)
		{
			var pageNumberList = new SortedSet<int> {currentPage};

			// Expand for current page
			for (var i = 1; i <= expandForCurrentPage; i++)
			{
				pageNumberList.Add(currentPage + i);
				pageNumberList.Add(currentPage - i);
			}

			// Expand for ending
			for (var i = 1; i <= expandForEnding; i++)
			{
				pageNumberList.Add(i);
				pageNumberList.Add(totalPage + 1 - i);
			}

			// Remove invalid items
			pageNumberList.RemoveWhere(i => i < 1 || i > totalPage);

			var lastPageNumber = 0;

			foreach (var i in pageNumberList)
			{
				// Skipped some item
				if (i - lastPageNumber > 1)
				{
					yield return new PagerItem
					{
						ItemType = PagerItemType.Omitted,
						PageNumber = -1
					};
				}

				yield return new PagerItem
				{
					// is current page
					ItemType = i == currentPage ? PagerItemType.Current : PagerItemType.Normal,
					PageNumber = i
				};

				// Set last page
				lastPageNumber = i;
			}

			// last page omit handling
			if (lastPageNumber < totalPage)
			{
				yield return new PagerItem
				{
					ItemType = PagerItemType.Omitted,
					PageNumber = -1
				};
			}
		}
开发者ID:sgjsakura,项目名称:AspNetCore,代码行数:65,代码来源:DefaultPagerListGenerator.cs

示例11: Main

        static void Main()
        {
            
            int n = int.Parse(Console.ReadLine());
            var noIncommingEdges = new SortedSet<char>();

            for (int i = 0; i < n; i++)
            {
                string currentMessage = Console.ReadLine();
                Node previousNode = GetNodeByCharFromGraph(currentMessage[0]);
                for (int j = 1; j < currentMessage.Length; j++)
                {
                    Node currentNode = GetNodeByCharFromGraph(currentMessage[j]);

                    previousNode.Successors.Add(currentNode);
                    currentNode.Parents.Add(previousNode);

                    previousNode = currentNode;
                }
            }

            foreach (var node in graph.Values)
            {
                if (node.Parents.Count == 0)
                {
                    noIncommingEdges.Add(node.Value);
                }
            }

            var result = new List<char>();

            while (noIncommingEdges.Count > 0)
            {
                var currentNodeSymbol = noIncommingEdges.Min;
                noIncommingEdges.Remove(currentNodeSymbol);

                result.Add(currentNodeSymbol);

                var currentNode = graph[currentNodeSymbol];
                var children = currentNode.Successors.ToList();
                foreach (var child in children)
                {
                    child.Parents.Remove(currentNode);
                    currentNode.Successors.Remove(child);

                    if (child.Parents.Count == 0)
                    {
                        noIncommingEdges.Add(child.Value);
                    }
                }
            }

            Console.WriteLine(String.Join("", result));


        }
开发者ID:nzhul,项目名称:TelerikAcademy,代码行数:56,代码来源:Program.cs

示例12: Initialize

        public override void Initialize()
        {
            base.Initialize();

            new ControlHandler(this);

            _collided = new SortedSet<string>();
            Page p = new Page(this, "Page");
            p.Show();
            _collidedLabel = new Label(p, "CollidedLabel", new Point(0, 0));
            _collidedLabel.Body.Position = new Vector2(10, 560);
            for (int x = 0; x < 3; x++)
            {
                ResolutionTestNode c = new ResolutionTestNode(this, "A" + x);
                c.Collision.Group.AddMask(0);
                c.Collision.Pair.AddMask(0);
                c.Collision.Pair.AddMask(2);
                c.Collision.ResolutionGroup.AddMask(0);
                c.Collision.ResolutionGroup.AddMask(1);
                c.Collision.ResolutionGroup.AddMask(2);
                c.Collision.CollideEvent +=
                    manifold =>
                        _collided.Add(manifold.A != c.Collision ? manifold.A.Parent.Name : manifold.B.Parent.Name);
                c.Collision.Debug = true;
                c.Body.Position = new Vector2(30, 80 * x + 20);
            }
            for (int x = 0; x < 3; x++)
            {
                ResolutionTestNode c = new ResolutionTestNode(this, "B" + x);
                c.Collision.Group.AddMask(1);
                c.Collision.Pair.AddMask(0);
                c.Collision.Pair.AddMask(2);
                c.Collision.ResolutionGroup.AddMask(0);
                c.Collision.CollideEvent += manifold => _collided.Add(manifold.A != c.Collision ? manifold.A.Parent.Name : manifold.B.Parent.Name);
                c.Collision.Debug = true;
                c.Body.Position = new Vector2(510, 80 * x + 20);
                c.Color = Color.Orange;
                c.HoverColor = Color.Violet;
            }

            for (int x = 0; x < 3; x++)
            {
                ResolutionTestNode c = new ResolutionTestNode(this, "C" + x);
                c.Collision.Group.AddMask(2);
                c.Collision.Pair.AddMask(0);
                c.Collision.Pair.AddMask(1);
                c.Collision.ResolutionGroup.AddMask(0);
                c.Collision.ResolutionGroup.AddMask(1);
                c.Collision.CollideEvent += manifold => _collided.Add(manifold.A != c.Collision ? manifold.A.Parent.Name : manifold.B.Parent.Name);
                c.Collision.Immovable = true;
                c.Collision.Debug = true;
                c.Body.Position = new Vector2(50 + x * 70, 450);
                c.Color = Color.Green;
                c.HoverColor = Color.DarkBlue;
            }
        }
开发者ID:redcodefinal,项目名称:EntityEngineV4TestBed,代码行数:56,代码来源:ResolutionTestState.cs

示例13: WordBreakIITestErrorCase

 public void WordBreakIITestErrorCase()
 {
     WordBreakII wb = new WordBreakII();
     SortedSet<string> wordset = new SortedSet<string>();
     wordset.Add("aaaa");
     wordset.Add("aaa");
     List<string> strs = (List<string>)wb.WordBreak("aaaaaaa", wordset);
     List<string> target = new List<string>() { "aaaa aaa", "aaa aaaa" };
     Assert.IsTrue(isListEqual(target, strs));
 }
开发者ID:crysisfair,项目名称:AlgorithmLearning,代码行数:10,代码来源:WordBreakIITest.cs

示例14: Search

        public static Stack<Square> Search(Map map, Square source, Square target, Func<Square, Square, int> heuristic)
        {
            Dictionary<Square, Square> parents = new Dictionary<Square, Square>();
            HashSet<Square> closed = new HashSet<Square>();
            SortedSet<Square> open = new SortedSet<Square>();

            source.Score.Cost = 0;
            source.Score.Estimate = heuristic(source, target);
            open.Add(source);

            while (open.Count > 0)
            {

                // Get node with lowest f(x) score
                Square current = open.First();

                if (current == target)
                    break;

                // Transfer node to closed set
                open.Remove(current);
                closed.Add(current);

                // Examine neighbors
                foreach (Square neighbor in map.GetNeighbors(current))
                {
                    // Check if node is already processed or not passable
                    if (closed.Contains(neighbor) || (neighbor != target && !neighbor.IsPassable))
                        continue;

                    // Tentative g score
                    float g = current.Score.Cost + 1;

                    // Add (new) node to open
                    if (!open.Contains(neighbor))
                    {
                        parents[neighbor] = current;
                        neighbor.Score.Cost = g;
                        neighbor.Score.Estimate = heuristic(neighbor, target);
                        open.Add(neighbor);
                    }

                    // Updating existing node in open
                    else if (g < neighbor.Score.Cost)
                    {
                        open.Remove(neighbor);
                        parents[neighbor] = current;
                        neighbor.Score.Cost = g;
                        open.Add(neighbor);
                    }
                }
            }

            return ReconstructPath(parents, target);
        }
开发者ID:tvdburgt,项目名称:ants,代码行数:55,代码来源:AStar.cs

示例15: Store

        private int _maxProcessingTimeFromStart; //The answer to the big question

        #endregion Fields

        #region Constructors

        public Store(int cashierCount)
        {
            Debug.Assert(cashierCount > 0, "Invalid number of cashiers specified. Must be greater than zero");
            CashierIdGenerator.Reset();
            _cashiers = new SortedSet<ICashier>();
            for (int i = 0; i < cashierCount - 1; i++)
            {
                _cashiers.Add(new Cashier(CashierIdGenerator.NextCashierId));
            }
            _cashiers.Add(new CashierTrainee(CashierIdGenerator.NextCashierId));
        }
开发者ID:tanveeransari,项目名称:Dumbekv,代码行数:17,代码来源:Store.cs


注:本文中的SortedSet.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。