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


C# CircularBuffer.Enqueue方法代码示例

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


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

示例1: TestEnumerationWhenFull

 public void TestEnumerationWhenFull()
 {
     var buffer = new CircularBuffer<long>(3);
     Assert.AreEqual(default(long), buffer.Enqueue(1));
     Assert.AreEqual(default(long), buffer.Enqueue(2));
     Assert.AreEqual(default(long), buffer.Enqueue(3));
     var i = 0;
     foreach (var value in buffer)
         Assert.AreEqual(++i, value);
     Assert.AreEqual(i, 3);
 }
开发者ID:nachocove,项目名称:JetBlack.Caching,代码行数:11,代码来源:CircularBufferFixture.cs

示例2: TestUnderwrite

 public void TestUnderwrite()
 {
     var buffer = new CircularBuffer<long>(5);
     Assert.AreEqual(default(long), buffer.Enqueue(1));
     Assert.AreEqual(default(long), buffer.Enqueue(2));
     Assert.AreEqual(default(long), buffer.Enqueue(3));
     Assert.AreEqual(3, buffer.Count);
     Assert.AreEqual(1, buffer.Dequeue());
     Assert.AreEqual(2, buffer.Dequeue());
     Assert.AreEqual(3, buffer.Dequeue());
     Assert.AreEqual(0, buffer.Count);
 }
开发者ID:nachocove,项目名称:JetBlack.Caching,代码行数:12,代码来源:CircularBufferFixture.cs

示例3: TestDecreaseCapacityWhenFull

 public void TestDecreaseCapacityWhenFull()
 {
     var buffer = new CircularBuffer<long>(3);
     Assert.AreEqual(default(long), buffer.Enqueue(1));
     Assert.AreEqual(default(long), buffer.Enqueue(2));
     Assert.AreEqual(default(long), buffer.Enqueue(3));
     Assert.AreEqual(3, buffer.Count);
     buffer.Capacity = 2;
     Assert.AreEqual(2, buffer.Count);
     Assert.AreEqual(1, buffer.Dequeue());
     Assert.AreEqual(2, buffer.Dequeue());
     Assert.AreEqual(0, buffer.Count);
 }
开发者ID:nachocove,项目名称:JetBlack.Caching,代码行数:13,代码来源:CircularBufferFixture.cs

示例4: CircularBuffer_Enqueue

        public void CircularBuffer_Enqueue()
        {
            var buffer = new CircularBuffer<string>(10);
            buffer.Enqueue("test");
            buffer.Enqueue("string");

            CollectionAssert.AreEqual(new[] { "test", "string" }, buffer.ToArray());
            Assert.AreEqual(2, buffer.Count);
            Assert.AreEqual(10, buffer.Capacity);
            Assert.AreEqual(0, buffer.Head);
            Assert.AreEqual(2, buffer.Tail);
            Assert.IsTrue(buffer.Contains("string"));
            Assert.IsFalse(buffer.Contains("other string"));
        }
开发者ID:joaope,项目名称:DataStructuresNET,代码行数:14,代码来源:CircularBufferTest.cs

示例5: CircularBuffer_EnqueueAfterTrimExcess

        public void CircularBuffer_EnqueueAfterTrimExcess()
        {
            var buffer = new CircularBuffer<string>(10);
            buffer.EnqueueRange(new[] { "a", "b", "c" }, 0, 3);

            buffer.TrimExcess();
            buffer.Enqueue("z");

            CollectionAssert.AreEqual(new[] { "z", "b", "c" }, buffer.ToArray());
            Assert.AreEqual(3, buffer.Count);
            Assert.AreEqual(3, buffer.Capacity);
            Assert.AreEqual(0, buffer.Head);
            Assert.AreEqual(1, buffer.Tail);
            Assert.IsTrue(buffer.Contains("z"));
            Assert.IsFalse(buffer.Contains("a"));
        }
开发者ID:joaope,项目名称:DataStructuresNET,代码行数:16,代码来源:CircularBufferTest.cs

示例6: UnitOracle

        private UnitOracle(WoWUnit unit, Watch watchFlags)
        {
            if (unit != null) {
                this.Unit = unit;

                Flags = watchFlags;

                if (instances.ContainsKey(unit.Guid))
                    throw new NotSupportedException();

                instances[unit.Guid] = this;

                if ((Flags & Watch.HealthVariance) == Watch.HealthVariance) {
                    health = new CircularBuffer<double>(WINDOW_SIZE);
                    for (var i = 0; i < WINDOW_SIZE; i++)
                        health.Enqueue((double)Unit.CurrentHealth);
                }
            }
        }
开发者ID:Asphodan,项目名称:Alphabuddy,代码行数:19,代码来源:UnitOracle.cs

示例7: Close

 public void Close()
 {
     _log.Debug("Running: BlockingEnqueue");
     const int size = 10;
     _buf = new CircularBuffer<Object>(size);
     // add size element anc check that the size +1 add blocks 
     for (int i = 1; i < size; i++)
     {
         _buf.Enqueue(new object());
     }
     // check tha the buffer is now full 
     Thread t = new Thread(Go);
     t.Start();
     Thread.Sleep(1000);
     // the trhead t should block until the buffer is closed             
     Assert.IsTrue(t.ThreadState == ThreadState.WaitSleepJoin);
     _buf.Close();
     Thread.Sleep(100);
     // t should now be stopped 
     Assert.IsTrue(t.ThreadState == ThreadState.Stopped);           
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:21,代码来源:CircularBufferTest.cs

示例8: CircularBuffer_EnqueueOverwriteAllowed

        public void CircularBuffer_EnqueueOverwriteAllowed()
        {
            string[] data = { "a", "b", "c", "d" };
            var buffer = new CircularBuffer<string>(data.Length);
            buffer.EnqueueRange(data, 0, data.Length);

            buffer.Enqueue("z");

            CollectionAssert.AreEqual(new[] { "z", "b", "c", "d" }, buffer.ToArray());
            Assert.AreEqual(data.Length, buffer.Count);
            Assert.AreEqual(data.Length, buffer.Capacity);
            Assert.AreEqual(0, buffer.Head);
            Assert.AreEqual(1, buffer.Tail);
            Assert.IsTrue(buffer.Contains("z"));
            Assert.IsFalse(buffer.Contains("a"));
        }
开发者ID:joaope,项目名称:DataStructuresNET,代码行数:16,代码来源:CircularBufferTest.cs

示例9: CircularBuffer_EnqueueOverwriteNotAllowed

 public void CircularBuffer_EnqueueOverwriteNotAllowed()
 {
     int[] data = { 1, 2, 3, 4, 5 };
     var buffer = new CircularBuffer<int>(data.Length, false);
     buffer.EnqueueRange(data, 0, data.Length);
     buffer.Enqueue(10);
 }
开发者ID:joaope,项目名称:DataStructuresNET,代码行数:7,代码来源:CircularBufferTest.cs

示例10: InitPlayback

		/// <summary>
		/// Start Playback
		/// </summary>
		/// <param name="res"></param>
		public void InitPlayback(VideoBuffer videoBuffer) {
			if (videoBuffer == null) {
				throw new ArgumentNullException("videoBufferDescription");
			}
			VerifyAccess();
			
			TimeSpan renderinterval;
			try {
				int fps = AppDefaults.visualSettings.ui_video_rendering_fps;
				fps = (fps <= 0 || fps > 100) ? 100 : fps;
				renderinterval = TimeSpan.FromMilliseconds(1000 / fps);
			} catch {
				renderinterval = TimeSpan.FromMilliseconds(1000 / 30);
			}

			var cancellationTokenSource = new CancellationTokenSource();
			renderSubscription.Disposable = Disposable.Create(() => {
				cancellationTokenSource.Cancel();
			});
			var bitmap = PrepareForRendering(videoBuffer);
			var cancellationToken = cancellationTokenSource.Token;
			var dispatcher = Application.Current.Dispatcher;
			var renderingTask = Task.Factory.StartNew(() => {
				var statistics = new CircularBuffer<long>(100);
				using (videoBuffer.Lock()) {
					try {
						//start rendering loop
						while (!cancellationToken.IsCancellationRequested) {
							using (var processingEvent = new ManualResetEventSlim(false)) {
								dispatcher.BeginInvoke(() => {
									using (Disposable.Create(() => processingEvent.Set())) {
										if (!cancellationToken.IsCancellationRequested) {
											//update statisitc info
											statistics.Enqueue(Stopwatch.GetTimestamp());
											//evaluate averange rendering fps
											var ticksEllapsed = statistics.last - statistics.first;
											double avgFps = 0;
											if (ticksEllapsed > 0) {
												avgFps = ((double)statistics.length * (double)Stopwatch.Frequency) / (double)ticksEllapsed;
											}
											//render farme to screen
											DrawFrame(bitmap, videoBuffer, avgFps);
										}
									}
								});
								processingEvent.Wait(cancellationToken);
							}
							cancellationToken.WaitHandle.WaitOne(renderinterval);
						}
					} catch (OperationCanceledException) {
						//swallow exception
					} catch (Exception error) {
						dbg.Error(error);
					}
				}
			}, cancellationToken);
			
		}
开发者ID:zzilla,项目名称:ONVIF-Device-Manager,代码行数:62,代码来源:VideoPlayer.xaml.cs

示例11: UsageExample

        public void UsageExample()
        {
            // Create a buffer with a capacity of 5 items.
            var buffer = new CircularBuffer<long>(5);

            // Add three.
            foreach (var i in Enumerable.Range(1, 3))
                buffer.Enqueue(i);
            Debug.WriteLine(buffer);
            // Capacity=5, Count=3, Buffer=[1,2,3]

            // Add three more.
            foreach (var i in Enumerable.Range(4, 3))
                buffer.Enqueue(i);
            Debug.WriteLine(buffer);
            // Capacity=5, Count=5, Buffer=[2,3,4,5,6]

            // Remove the third.
            var value = buffer[3];
            buffer.RemoveAt(3);
            Debug.WriteLine(buffer);
            // Capacity=5, Count=4, Buffer=[2,3,4,6]

            // Re-insert it.
            buffer.Insert(3, value);
            Debug.WriteLine(buffer);
            // Capacity=5, Count=5, Buffer=[2,3,4,5,6]

            // Dequeue.
            Debug.Print("Value = {0}", buffer.Dequeue());
            // Value = 2
            Debug.WriteLine(buffer);
            // Capacity=5, Count=4, Buffer=[3,4,5,6]

            // Increase the capacity.
            buffer.Capacity = 6;
            Debug.WriteLine(buffer);
            // Capacity=6, Count=4, Buffer=[3,4,5,6]

            // Add three more.
            foreach (var i in Enumerable.Range(7, 3))
                buffer.Enqueue(i);
            Debug.WriteLine(buffer);
            // Capacity=6, Count=6, Buffer=[4,5,6,7,8,9]

            // Reduce the capacity.
            buffer.Capacity = 4;
            Debug.WriteLine(buffer);
            // Capacity=4, Count=4, Buffer=[4,5,6,7]

            // Clear the buffer.
            buffer.Clear();
            Debug.WriteLine(buffer);
            // Capacity=4, Count=0, Buffer=[]
        }
开发者ID:nachocove,项目名称:JetBlack.Caching,代码行数:55,代码来源:CircularBufferFixture.cs

示例12: TestRemoveAt

 public void TestRemoveAt()
 {
     var buffer = new CircularBuffer<long>(5);
     Assert.AreEqual(default(long), buffer.Enqueue(1));
     Assert.AreEqual(default(long), buffer.Enqueue(2));
     Assert.AreEqual(default(long), buffer.Enqueue(3));
     Assert.AreEqual(default(long), buffer.Enqueue(4));
     Assert.AreEqual(default(long), buffer.Enqueue(5));
     buffer.RemoveAt(buffer.IndexOf(2));
     buffer.RemoveAt(buffer.IndexOf(4));
     Assert.AreEqual(3, buffer.Count);
     Assert.AreEqual(1, buffer.Dequeue());
     Assert.AreEqual(3, buffer.Dequeue());
     Assert.AreEqual(5, buffer.Dequeue());
     Assert.AreEqual(0, buffer.Count);
     Assert.AreEqual(default(long), buffer.Enqueue(1));
     Assert.AreEqual(default(long), buffer.Enqueue(2));
     Assert.AreEqual(default(long), buffer.Enqueue(3));
     Assert.AreEqual(default(long), buffer.Enqueue(4));
     Assert.AreEqual(default(long), buffer.Enqueue(5));
     buffer.RemoveAt(buffer.IndexOf(1));
     buffer.RemoveAt(buffer.IndexOf(3));
     buffer.RemoveAt(buffer.IndexOf(5));
     Assert.AreEqual(2, buffer.Count);
     Assert.AreEqual(2, buffer.Dequeue());
     Assert.AreEqual(4, buffer.Dequeue());
     Assert.AreEqual(0, buffer.Count);
 }
开发者ID:nachocove,项目名称:JetBlack.Caching,代码行数:28,代码来源:CircularBufferFixture.cs


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