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


C# CircularBuffer.Dequeue方法代码示例

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


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

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

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

示例3: setHeaders

        public void setHeaders()
        {          
            _log.Debug("Running: setHeaders");
            IClientSession ssn = Client.CreateSession(0);
            ssn.QueueDeclare("queue1");
            ssn.ExchangeBind("queue1", "amq.direct", "queue1");
            ssn.Sync();
            CircularBuffer<IMessage> buff = new CircularBuffer<IMessage>(10); 
            SyncListener listener = new SyncListener(ssn, buff);
            ssn.AttachMessageListener(listener, "queue1");
            ssn.MessageSubscribe("queue1");

            IMessage message = new org.apache.qpid.client.Message();
            message.DeliveryProperties.SetRoutingKey("queue1");
            const long someLong = 14444444;
            message.ApplicationHeaders.Add("someLong", someLong);
            const int someInt = 14;
            message.ApplicationHeaders.Add("soneInt", someInt);
            const float someFloat = 14.001F;
            message.ApplicationHeaders.Add("soneFloat", someFloat);
            const double someDouble = 14.5555555;
            message.ApplicationHeaders.Add("someDouble", someDouble);
            const byte someByte = 2;
            message.ApplicationHeaders.Add("someByte", someByte);
            const string someString = "someString";
            message.ApplicationHeaders.Add("someString", someString);
            const char someChar = 'a';
            message.ApplicationHeaders.Add("someChar", someChar);
            const Boolean someBoolean = true;
            message.ApplicationHeaders.Add("someBoolean", someBoolean);

            // transfer the message 
            ssn.MessageTransfer("amq.direct", message); 

            // get the message and check the headers 
            IMessage messageBack = buff.Dequeue();
            Assert.IsTrue(((string) messageBack.ApplicationHeaders["someString"]).Equals(someString));
            Assert.IsTrue(((char)messageBack.ApplicationHeaders["someChar"]).Equals(someChar));
            Assert.IsTrue((long)messageBack.ApplicationHeaders["someLong"] == someLong);
            Assert.IsTrue((int)messageBack.ApplicationHeaders["soneInt"] == someInt);           
            Assert.IsTrue((double)messageBack.ApplicationHeaders["someDouble"] == someDouble);
            Assert.IsTrue((byte) messageBack.ApplicationHeaders["someByte"] == someByte);
            Assert.IsTrue((Boolean)messageBack.ApplicationHeaders["someBoolean"]);
            // c# has an conversion precision issue with decimal 
            Assert.IsTrue((float) messageBack.ApplicationHeaders["soneFloat"] <= someFloat);
            float b = (float) messageBack.ApplicationHeaders["soneFloat"];
            Assert.IsTrue(Convert.ToInt32(b) == Convert.ToInt32(someFloat));
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:48,代码来源:ApplicationHeaders.cs

示例4: CircularBuffer_Dequeue

        public void CircularBuffer_Dequeue()
        {
            int[] data = { 0, 1, 2, 3 };
            var buffer = new CircularBuffer<int>(data.Length);
            buffer.EnqueueRange(data, 0, data.Length);

            buffer.Dequeue();

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

示例5: BlockingEnqueue

 public void BlockingEnqueue()
 {
     _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(100);
     // the trhead t should block until an element is dequeued 
     Assert.IsTrue(t.ThreadState == ThreadState.WaitSleepJoin);           
     _buf.Dequeue();
     // t should now be stopped 
     Thread.Sleep(100);
     Assert.IsTrue(t.ThreadState == ThreadState.Stopped);           
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:21,代码来源:CircularBufferTest.cs

示例6: CircularBuffer_DequeueWhenEmpty

 public void CircularBuffer_DequeueWhenEmpty()
 {
     var buffer = new CircularBuffer<string>();
     buffer.Dequeue();
 }
开发者ID:joaope,项目名称:DataStructuresNET,代码行数:5,代码来源:CircularBufferTest.cs

示例7: processRate

 private double processRate(int size, string queue)
 {
     CircularBuffer<IMessage> buffer = new CircularBuffer<IMessage>(100);
     IMessageListener listener = new SyncListener(buffer);
     string localQueue = "queue-" + UUID.RandomUuid();
     Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
     Session.ExchangeBind(localQueue, "amq.direct", queue);
     Session.AttachMessageListener(listener, localQueue);
     Session.MessageSubscribe(localQueue);
     double rate = 0;
     RangeSet range = new RangeSet();
     for (int i = 0; i < size; ++i)
     {
         IMessage m = buffer.Dequeue();
         range.Add(m.Id);
         BinaryReader reader = new BinaryReader(m.Body, Encoding.UTF8);
         byte[] body = new byte[m.Body.Length - m.Body.Position];
         reader.Read(body, 0, body.Length);
         rate += BitConverter.ToDouble(body,0);
     }
     Session.MessageAccept(range);
     return rate;
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:23,代码来源:PerfTest.cs

示例8: process

 private void process(int size, string queue)
 {
     CircularBuffer<IMessage> buffer = new CircularBuffer<IMessage>(100);
     IMessageListener listener = new SyncListener(buffer);
     string localQueue = "queue-" + UUID.RandomUuid();
     Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
     Session.ExchangeBind(localQueue, "amq.direct", queue);
     Session.AttachMessageListener(listener, localQueue);
     Session.MessageSubscribe(localQueue);
     for (int i = 0; i < size; ++i)
     {
         buffer.Dequeue();
     }
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:14,代码来源:PerfTest.cs

示例9: Start

        public override void Start()
        {
            byte[] data = new byte[Options.Size];
            // randomly populate data 
            Random r = new Random(34);
            r.NextBytes(data);
            IMessage message = new Message();
            message.AppendData(data);

            message.DeliveryProperties.SetRoutingKey(_key);

            if (Options.Durable)
                message.DeliveryProperties.SetDeliveryMode(MessageDeliveryMode.PERSISTENT);

            if (Options.Tx > 0)
            {
                Session.TxSelect();
                Session.Sync();
            }

            CircularBuffer<IMessage> buffer = new CircularBuffer<IMessage>(100);
            // Create a listener and subscribe it to the queue named "pub_start"          
            IMessageListener listener = new SyncListener(buffer);
            string localQueue = "localQueue-" + UUID.RandomUuid().ToString();
            Session.QueueDeclare(localQueue, null, null, Option.AUTO_DELETE);
            Session.ExchangeBind(localQueue, "amq.direct", "pub_start");
            Session.AttachMessageListener(listener, localQueue);
            Session.MessageSubscribe(localQueue);
            if (Options.Tx > 0)
            {
                Session.TxCommit();
                Session.Sync();
            }
            buffer.Dequeue();

            for (int j = 0; j < Options.Iterations; ++j)
            {
                DateTime start = DateTime.Now;                
                for (long i = 0; i < Options.Count; ++i)
                {
                    Session.MessageTransfer(_exchange, message);

                    if (Options.SyncPub)
                    {
                        Session.Sync();
                    }
                    if (Options.Tx > 0 && (i + 1)%Options.Tx == 0)
                    {
                        Session.TxSelect();
                        Session.Sync();
                    }
                    if (Options.IntervalPub > 0)
                    {
                        Thread.Sleep((int) Options.IntervalSub*1000);
                    }
                }
                Session.Sync();
                DateTime end = DateTime.Now;

                // Report to publisher.
                message.DeliveryProperties.SetRoutingKey("pub_done");
                message.ClearData();
                double time = end.Subtract(start).TotalMilliseconds;
                byte[] rate = BitConverter.GetBytes( Options.Count / time );
                message.AppendData(rate);
                Session.MessageTransfer("amq.direct", message);
                if (Options.Tx > 0)
                {
                    Session.TxSelect();
                    Session.Sync();
                }
            }
            Session.Close();
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:74,代码来源:PerfTest.cs

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

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