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


C# SortedSet.RemoveWhere方法代码示例

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


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

示例1: 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

示例2: TestRemoveWhere

        public static void TestRemoveWhere()
        {
            SortedSet<int> sortedSet = new SortedSet<int>();
            for (int i = 0; i < 5000; i++)
            {
                sortedSet.Add(i);
            }

            int removed = sortedSet.RemoveWhere(delegate (int x) { if (x < 2500) return true; else return false; });

            Assert.Equal(2500, removed); //"Did not remove according to predicate"
            Assert.Equal(2500, sortedSet.Count); //"Did not remove according to predicate"
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:13,代码来源:SortedSetSpecificTests.cs

示例3: CommitTransaction

        public byte[] CommitTransaction(SortedSet<BaseDataObjectVersion> objects)
        {
            Log.WriteLine ("Database.CommitTransaction()");
            int oc = objects.Count;
            objects.RemoveWhere (obj => obj.ChunkID != null);
            Log.WriteLine ("Ommitting {0} objects in commit", oc - objects.Count);
            System.IO.MemoryStream MS = new System.IO.MemoryStream ();
            System.IO.MemoryStream MSRP = new System.IO.MemoryStream ();
            System.IO.BinaryWriter MSBW = new System.IO.BinaryWriter (MS);
            SortedSet<byte[]> dependencies = new SortedSet<byte[]> (BD2.Core.ByteSequenceComparer.Shared);
            ChunkHeaderv1 ch = new ChunkHeaderv1 (DateTime.UtcNow, "");
            MSBW.Write (ch.Version);
            byte[] chbytes = ch.Serialize ();
            MSBW.Write (chbytes.Length);
            MSBW.Write (chbytes);
            MSBW.Write (1);//section count
            Log.WriteLine ("{0} sections", 1);
            int n = 0;
            //foreach (var tup in data) {
            MSBW.Write (1);
            Log.WriteLine ("Section version is {0}", 1);
            System.Collections.Generic.SortedDictionary <BaseDataObjectVersion, LinkedListNode<BaseDataObjectVersion>> ss = new  System.Collections.Generic.SortedDictionary <BaseDataObjectVersion, LinkedListNode<BaseDataObjectVersion>> ();
            System.Collections.Generic.LinkedList <BaseDataObjectVersion> ll = new LinkedList<BaseDataObjectVersion> ();
            foreach (BaseDataObjectVersion bdo in objects) {
                if (!ss.ContainsKey (bdo))
                    ss.Add (bdo, ll.AddLast (bdo));

                foreach (BaseDataObjectVersion dependency in bdo.GetDependenies ()) {
                    byte[] dep = dependency.ChunkID;
                    if (dep == null) {
                        if (ss.ContainsKey (bdo)) {

                        } else {

                            ss.Add (dependency, ll.AddBefore (ss [bdo], dependency));

                        }
                    } else {
                        if (!dependencies.Contains (dependency.ChunkID))
                            dependencies.Add (dependency.ChunkID);
                    }
                }
            }
            foreach (BaseDataObjectVersion bdo in ll) {
                n++;
                System.IO.MemoryStream MST = new System.IO.MemoryStream ();
                MST.Write (bdo.ObjectType.ToByteArray (), 0, 16);
                bdo.Serialize (MST, encryptedStorageManager);
                byte[] bytes = MST.ToArray ();
                Log.WriteLine ("object type+bytes: {0}", bytes.ToHexadecimal ());
                //Log.WriteLine ("Object of type {0} serialized to {1} bytes.", bdo.GetType ().FullName, bytes.Length);
                {
                    System.IO.MemoryStream MSC = new System.IO.MemoryStream ();
                    System.IO.BinaryWriter BWC = new System.IO.BinaryWriter (MSC);
                    BWC.Write (bytes.Length);
                    MSRP.Write (MSC.ToArray (), 0, 4);
                }

                MSRP.Write (bytes, 0, bytes.Length);
            }
            byte[] encoded = MSRP.ToArray ();
            Log.WriteLine ("{0} objects encoded in {1} bytes", objects.Count, encoded.Length);
            MSBW.Write (n);
            MSBW.Write (encoded.Length);
            MSBW.Write (encoded);
            Log.WriteLine ("encoded:{0}", encoded.ToHexadecimal ());
            //}
            if (n == 0) {
                Log.WriteLine ("No objects to save, nothing to do");
                return null;
            }
            System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create ();
            Log.WriteLine ("{0} dependencies", dependencies.Count);
            byte[][] deps = new byte [dependencies.Count][];
            int depid = 0;
            foreach (byte[] dep in dependencies)
                deps [depid++] = dep;
            Log.WriteLine ("Writing {0} bytes representing {1} objects to backend", MS.Length, n);
            byte[] buf = MS.ToArray ();
            byte[] chunkID = sha.ComputeHash (buf);
            foreach (var ds in dataStorage)
                Log.WriteLine ("We have: {0}", ds.Key.ToHexadecimal ());
            byte[] cus = userStorage.GetCommonStorage ();
            Log.WriteLine ("Common storage id is {0}", cus.ToHexadecimal ());
            if (!dataStorage.ContainsKey (cus)) {
                Log.WriteLine ("and we don't have it.");
                Log.WriteLine ("we only have:");
                foreach (var t in dataStorage)
                    Log.WriteLine ("    ID: {0}", t.Key.ToHexadecimal ());
            }
            dataStorage [cus].Push (chunkID, buf, deps, userStorage.Sign (chunkID));
            foreach (var bdo in objects) {
                bdo.SetChunkID (chunkID);
            }
            Log.WriteLine ("Chunk saved with ID:{0}", chunkID.ToHexadecimal ());
            return chunkID;
        }
开发者ID:vebin,项目名称:BD2,代码行数:97,代码来源:Database.cs

示例4: SendReliableMessage


//.........这里部分代码省略.........
                                     .ObserveOn(TaskPoolScheduler.Default)
                                     .Subscribe(async x =>
                                         {
                                             if (
                                                 x.BlockId < blocksCount
                                                 && !outMessageInfo.BlockConfirmed[x.BlockId]
                                                 )
                                             {
                                                 await outMessageInfo.ConfirmBlock(x.BlockId).ConfigureAwait(false);
                                                 lastBlockConfirmationTime = DateTime.UtcNow;
                                                 using (await blocksInProgressLockSem.GetDisposable().ConfigureAwait(false))
                                                 {
                                                     blocksInProgress.Remove(x.BlockId);
                                                 }
                                             }
                                         }
                                     )
                             )
                             {
                                 while (true)
                                 {
                                     compositeTokenSource.Token.ThrowIfCancellationRequested();
                                     IEnumerable<int> blocksToSend;
                                     using (
                                         await
                                             blocksInProgressLockSem.GetDisposable(token: compositeTokenSource.Token)
                                                 .ConfigureAwait(false))
                                     {
                                         if (
                                             blocksInProgress.Count == 0
                                             && outMessageInfo.BlockConfirmed.All(x => x)
                                             )
                                             break;
                                         blocksInProgress.RemoveWhere(
                                             i =>
                                                 DateTime.UtcNow >
                                                 (
                                                     blockSentTimes[i]
                                                     + TimeSpan.FromSeconds(
                                                         _settings
                                                             .ConfirmationOneBlockTimeoutSeconds
                                                         )
                                                     )
                                             );
                                         blocksToSend = Enumerable.Range(0, (int)blocksCount)
                                             .Where(
                                                 i =>
                                                     !blocksInProgress.Contains((uint)i)
                                                     && !outMessageInfo.BlockConfirmed[i]
                                             )
                                             .Take(
                                                 Math.Max(
                                                     0,
                                                     _settings.WindowSize
                                                     - blocksInProgress.Count
                                                     )
                                             );
                                     }
                                     foreach (int blockId in blocksToSend)
                                     {
                                         await SendBlock(
                                             destination,
                                             messageId,
                                             (uint)blockId
                                         ).ConfigureAwait(false);
                                         await outMessageInfo.SendBlock(
开发者ID:z0rg1nc,项目名称:SamHelperLib,代码行数:67,代码来源:ReliableSamHelper_Out.cs


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