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


C# RangeCollection.Add方法代码示例

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


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

示例1: AddTest3

 public void AddTest3()
 {
     var c = new RangeCollection();
     var ranges = c.Ranges;
     c.Add(new AddressRange(0, 100));
     c.Add(new AddressRange(200, 300));
     c.Add(new AddressRange(150, 600));
     Assert.Equal(2, ranges.Count);
     Assert.Equal(new AddressRange(0, 100), ranges[0]);
     Assert.Equal(new AddressRange(150, 600), ranges[1]);
     c.Add(new AddressRange(102, 500));
     Assert.Equal(2, ranges.Count);
     Assert.Equal(new AddressRange(102, 600), ranges[1]);
     c.Add(new AddressRange(400, 700));
     Assert.Equal(2, ranges.Count);
     Assert.Equal(new AddressRange(102, 700), ranges[1]);
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:17,代码来源:RangeCollectionTests.cs

示例2: AddTest3

 public void AddTest3()
 {
     RangeCollection c = new RangeCollection();
     List<AddressRange> ranges = c.Ranges;
     c.Add(new AddressRange(0, 100));
     c.Add(new AddressRange(200, 300));
     c.Add(new AddressRange(150, 600));
     Assert.AreEqual(2, ranges.Count, "#1");
     Assert.AreEqual(new AddressRange(0, 100), ranges[0], "#1b");
     Assert.AreEqual(new AddressRange(150, 600), ranges[1], "#1c");
     c.Add(new AddressRange(102, 500));
     Assert.AreEqual(2, ranges.Count, "#2");
     Assert.AreEqual(new AddressRange(102, 600), ranges[1], "#2b");
     c.Add(new AddressRange(400, 700));
     Assert.AreEqual(2, ranges.Count, "#3");
     Assert.AreEqual(new AddressRange(102, 700), ranges[1], "#3b");
 }
开发者ID:JacklEventreur,项目名称:monotorrent,代码行数:17,代码来源:RangeCollectionTests.cs

示例3: LargeSequentialContains

        public void LargeSequentialContains ()
        {
            RangeCollection range = new RangeCollection ();
            int i, n = 1000000;

            for (i = 0; i < n; i++) {
                range.Add (i);
            }

            for (i = 0; i < n; i++) {
                Assert.AreEqual (true, range.Contains (i));
            }
        }
开发者ID:rubenv,项目名称:tripod,代码行数:13,代码来源:RangeCollectionTests.cs

示例4: AddRangeSpecifier

        public static void AddRangeSpecifier(this RangeCollection self, string specifier)
        {
            if (self == null)
                throw new ArgumentNullException("self");

            if (specifier == null)
                throw new ArgumentNullException("specifier");

            string[] list = specifier.Split(',');

            RangeCollection staging = new RangeCollection(self.Minimum, self.Maximum);

            foreach (string i in list)
            {
                Match match = rangeRegex.Match(i);

                if (!match.Success)
                    ThrowBadRangeSpecifier(specifier);

                if (match.Groups["single"].Success)
                {
                    staging.Add(int.Parse(match.Groups["single"].Value));
                }
                else
                {
                    int start = self.Minimum;
                    int end = self.Maximum;
                    int step = 1;

                    if (match.Groups["step"].Success)
                        step = int.Parse(match.Groups["step"].Value);

                    if (match.Groups["start"].Success)
                    {
                        start = int.Parse(match.Groups["start"].Value);
                        end = int.Parse(match.Groups["end"].Value);
                    }

                    if (end < start)
                        ThrowBadRangeSpecifier(specifier);

                    for (int j = start; j <= end; j += step)
                        staging.Add(j);
                }
            }

            foreach (int i in staging)
                self.Add(i);
        }
开发者ID:cdhowie,项目名称:Cdh.Toolkit,代码行数:49,代码来源:RangeCollectionExtensions.cs

示例5: AddTest

 public void AddTest()
 {
     RangeCollection c = new RangeCollection();
     c.Add(new AddressRange(50, 50));
     c.Add(new AddressRange(50, 50));
     Assert.AreEqual(1, c.Ranges.Count, "#1");
     c.Add(new AddressRange(50, 51));
     Assert.AreEqual(1, c.Ranges.Count, "#2");
     c.Add(new AddressRange(51, 51));
     Assert.AreEqual(new AddressRange(50, 51), c.Ranges[0], "#2b");
     c.Add(new AddressRange(50, 50));
     c.Add(new AddressRange(49, 50));
     Assert.AreEqual(1, c.Ranges.Count, "#3");
     Assert.AreEqual(new AddressRange(49, 51), c.Ranges[0], "#3b");
     c.Add(new AddressRange(45, 47));
     Assert.AreEqual(2, c.Ranges.Count, "#4");
     Assert.AreEqual(new AddressRange(49, 51), c.Ranges[1], "#4b");
     c.Add(new AddressRange(47, 49));
     Assert.AreEqual(1, c.Ranges.Count, "#5");
     Assert.AreEqual(new AddressRange(45, 51), c.Ranges[0], "#4b");
 }
开发者ID:JacklEventreur,项目名称:monotorrent,代码行数:21,代码来源:RangeCollectionTests.cs

示例6: AddTest

 public void AddTest()
 {
     var c = new RangeCollection();
     c.Add(new AddressRange(50, 50));
     c.Add(new AddressRange(50, 50));
     Assert.Equal(1, c.Ranges.Count);
     c.Add(new AddressRange(50, 51));
     Assert.Equal(1, c.Ranges.Count);
     c.Add(new AddressRange(51, 51));
     Assert.Equal(new AddressRange(50, 51), c.Ranges[0]);
     c.Add(new AddressRange(50, 50));
     c.Add(new AddressRange(49, 50));
     Assert.Equal(1, c.Ranges.Count);
     Assert.Equal(new AddressRange(49, 51), c.Ranges[0]);
     c.Add(new AddressRange(45, 47));
     Assert.Equal(2, c.Ranges.Count);
     Assert.Equal(new AddressRange(49, 51), c.Ranges[1]);
     c.Add(new AddressRange(47, 49));
     Assert.Equal(1, c.Ranges.Count);
     Assert.Equal(new AddressRange(45, 51), c.Ranges[0]);
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:21,代码来源:RangeCollectionTests.cs

示例7: AddTest2

 public void AddTest2()
 {
     RangeCollection c = new RangeCollection();
     List<AddressRange> ranges = c.Ranges;
     c.Add(new AddressRange(0, 100));
     c.Add(new AddressRange(101, 200));
     Assert.AreEqual(1, ranges.Count, "#1");
     Assert.AreEqual(new AddressRange(0, 200), ranges[0], "#1b");
     c.Add(new AddressRange(300, 400));
     c.Add(new AddressRange(500, 600));
     Assert.AreEqual(3, ranges.Count, "#2");
     c.Add(new AddressRange(50, 205));
     Assert.AreEqual(3, ranges.Count, "#3");
     Assert.AreEqual(new AddressRange(0, 205), ranges[0], "#3b");
     c.Add(new AddressRange(-100, -1));
     Assert.AreEqual(3, ranges.Count, "#4");
     Assert.AreEqual(new AddressRange(-100, 205), ranges[0], "#4b");
     c.Add(new AddressRange(206, 299));
     Assert.AreEqual(2, ranges.Count, "#5");
     Assert.AreEqual(new AddressRange(-100, 400), ranges[0], "#5b");
     c.Add(new AddressRange(0, 600));
     Assert.AreEqual(1, ranges.Count, "#6");
     Assert.AreEqual(new AddressRange(-100, 600), ranges[0], "#6b");
 }
开发者ID:JacklEventreur,项目名称:monotorrent,代码行数:24,代码来源:RangeCollectionTests.cs

示例8: AddTest2

 public void AddTest2()
 {
     var c = new RangeCollection();
     var ranges = c.Ranges;
     c.Add(new AddressRange(0, 100));
     c.Add(new AddressRange(101, 200));
     Assert.Equal(1, ranges.Count);
     Assert.Equal(new AddressRange(0, 200), ranges[0]);
     c.Add(new AddressRange(300, 400));
     c.Add(new AddressRange(500, 600));
     Assert.Equal(3, ranges.Count);
     c.Add(new AddressRange(50, 205));
     Assert.Equal(3, ranges.Count);
     Assert.Equal(new AddressRange(0, 205), ranges[0]);
     c.Add(new AddressRange(-100, -1));
     Assert.Equal(3, ranges.Count);
     Assert.Equal(new AddressRange(-100, 205), ranges[0]);
     c.Add(new AddressRange(206, 299));
     Assert.Equal(2, ranges.Count);
     Assert.Equal(new AddressRange(-100, 400), ranges[0]);
     c.Add(new AddressRange(0, 600));
     Assert.Equal(1, ranges.Count);
     Assert.Equal(new AddressRange(-100, 600), ranges[0]);
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:24,代码来源:RangeCollectionTests.cs

示例9: Refresh

        public void Refresh ()
        {
            int index = current_track == null ? Count : TrackModel.IndexOf (current_track);

            // If the current track is not playing refresh it too.
            if (current_track != null && !ServiceManager.PlayerEngine.IsPlaying (current_track)) {
                index--;
            }

            if (index + 1 < Count) {
                // Get the ViewOrder of the current_track
                long current_view_order = CurrentTrackViewOrder;

                // Get the list of generated tracks.
                var generated = new HashSet<long> ();
                foreach (long trackID in ServiceManager.DbConnection.QueryEnumerable<long> ( @"
                    SELECT TrackID
                    FROM CorePlaylistEntries
                    WHERE PlaylistID = ? AND Generated = 1 AND ViewOrder >= ?",
                    DbId, current_view_order)) {

                    generated.Add (trackID);
                }

                // Collect the indices of all generated tracks.
                var ranges = new RangeCollection ();
                for (int i = index + 1; i < Count; i++) {
                    if (generated.Contains (((DatabaseTrackInfo)TrackModel[i]).TrackId)) {
                        ranges.Add (i);
                    }
                }

                bool removed = false;
                foreach (var range in ranges.Ranges) {
                    RemoveTrackRange (DatabaseTrackModel, range);
                    removed = true;
                }

                if (removed) {
                    OnTracksRemoved ();
                }
            } else if (Count == 0 || current_track == null) {
                UpdatePlayQueue ();
            }
        }
开发者ID:petejohanson,项目名称:banshee,代码行数:45,代码来源:PlayQueueSource.cs

示例10: MoveExistingItems

		void MoveExistingItems (int index, int offset)
		{
			// This is a little horrible. I should really collapse the existing
			// RangeCollection so that every > the current index is decremented by 1.
			// This is easier for now though. I may think of a better way later on.
			RangeCollection newRanges = new RangeCollection ();
			List <int> list = new List<int> ();
			for (int i = 0; i < RealizedElements.Count; i++)
				list.Add (RealizedElements [i]);
			
			if (offset > 0)
				list.Reverse ();

			foreach (int i in list) {
				int oldIndex = i;
				if (oldIndex < index) {
					newRanges.Add (oldIndex);
				} else {
					newRanges.Add (oldIndex + offset);
					var container = ContainerIndexMap [oldIndex];
					ContainerIndexMap.Remove (container, oldIndex);
					ContainerIndexMap.Add (container, oldIndex + offset);
				}
			}

			RealizedElements = newRanges;
		}
开发者ID:dfr0,项目名称:moon,代码行数:27,代码来源:ItemContainerGenerator.cs

示例11: LargeSequential

        public void LargeSequential ()
        {
            RangeCollection range = new RangeCollection ();
            int i, n = 1000000;

            for (i = 0; i < n; i++) {
                range.Add (i);
                Assert.AreEqual (1, range.RangeCount);
            }

            Assert.AreEqual (n, range.Count);

            i = 0;
            foreach (int j in range) {
                Assert.AreEqual (i++, j);
            }

            Assert.AreEqual (n, i);
        }
开发者ID:rubenv,项目名称:tripod,代码行数:19,代码来源:RangeCollectionTests.cs

示例12: RemoveTest

        public void RemoveTest()
        {
            var c = new RangeCollection();
            c.Add(new AddressRange(0, 100));
            c.Remove(new AddressRange(50, 50));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 49), c.Ranges[0]);
            Assert.Equal(new AddressRange(51, 100), c.Ranges[1]);

            c.Remove(new AddressRange(50, 55));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 49), c.Ranges[0]);
            Assert.Equal(new AddressRange(56, 100), c.Ranges[1]);

            c.Remove(new AddressRange(45, 60));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(45, 60));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(0, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(-100, 5));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(6, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(6, 15));
            Assert.Equal(2, c.Ranges.Count);
            Assert.Equal(new AddressRange(16, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 100), c.Ranges[1]);

            c.Remove(new AddressRange(70, 80));
            Assert.Equal(3, c.Ranges.Count);
            Assert.Equal(new AddressRange(16, 44), c.Ranges[0]);
            Assert.Equal(new AddressRange(61, 69), c.Ranges[1]);
            Assert.Equal(new AddressRange(81, 100), c.Ranges[2]);
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:40,代码来源:RangeCollectionTests.cs

示例13: IPAddressRanges

        public void IPAddressRanges ()
        {
            RangeCollection ranges = new RangeCollection ();

            int start = GetAddress ("127.0.0.1");
            int end = GetAddress ("127.0.0.50");

            for (int i = start; i <= end; i++) {
                ranges.Add (i);
            }

            Assert.IsTrue (ranges.Contains (GetAddress ("127.0.0.15")));
            Assert.IsFalse (ranges.Contains (GetAddress ("127.0.0.0")));
            Assert.IsFalse (ranges.Contains (GetAddress ("127.0.0.51")));
        }
开发者ID:rubenv,项目名称:tripod,代码行数:15,代码来源:RangeCollectionTests.cs

示例14: _TestRanges

        private static void _TestRanges (RangeCollection range, int [] indexes)
        {
            foreach (int index in indexes) {
                range.Add (index);
            }

            Assert.AreEqual (indexes.Length, range.Count);

            Array.Sort (indexes);

            int i = 0;
            foreach (int index in range) {
                Assert.AreEqual (indexes[i++], index);
            }

            #pragma warning disable 0618

            i = 0;
            foreach (int index in range.Indexes) {
                Assert.AreEqual (indexes[i++], index);
            }

            for (i = 0; i < range.Indexes.Length; i++) {
                Assert.AreEqual (indexes[i], range.Indexes[i]);
            }

            #pragma warning restore 0618

        }
开发者ID:rubenv,项目名称:tripod,代码行数:29,代码来源:RangeCollectionTests.cs

示例15: ContainsTest

 public void ContainsTest()
 {
     var c = new RangeCollection();
     c.Add(new AddressRange(1, 100));
     c.Add(new AddressRange(-10, -1));
     for (var i = -15; i < 120; i++)
     {
         var shouldContain = (i >= -10 && i <= -1) || (i >= 1 && i <= 100);
         Assert.Equal(shouldContain, c.Contains(new AddressRange(i, i)));
     }
 }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:11,代码来源:RangeCollectionTests.cs


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