Beispiel #1
0
        public void TryActionTest()
        {
            var q = UnsafeMPMCQueue.Allocate <int>(16);

            //Inserts 10 items.
            SplitQueue(q);

            //Insert 6 more to fill the queue
            for (int i = 0; i < 6; i++)
            {
                UnsafeMPMCQueue.TryEnqueue(q, 999);
            }

            Assert.IsTrue(UnsafeMPMCQueue.TryPeek(q, out int result));
            Assert.AreEqual(0, result);

            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(UnsafeMPMCQueue.TryDequeue(q, out int val));
                Assert.AreEqual(i, val);
            }

            //Empty 6 last items
            for (int i = 0; i < 6; i++)
            {
                Assert.IsTrue(UnsafeMPMCQueue.TryDequeue(q, out int val));
            }

            //Empty queue
            Assert.IsFalse(UnsafeMPMCQueue.TryPeek(q, out int res));

            UnsafeMPMCQueue.Free(q);
        }
Beispiel #2
0
        public void PeekTest()
        {
            var q = UnsafeMPMCQueue.Allocate <int>(10);

            for (int i = 0; i < 10; i++)
            {
                UnsafeMPMCQueue.TryEnqueue(q, (int)Math.Pow(i + 2, 2));
            }

            for (int i = 0; i < 10; i++)
            {
                UnsafeMPMCQueue.TryPeek(q, out int result);
                Assert.AreEqual(4, result);
            }

            //Verify no items are dequeued
            Assert.AreEqual(10, UnsafeMPMCQueue.GetCount(q));

            UnsafeMPMCQueue.Free(q);
        }
 public bool TryPeek(out T result)
 {
     return(UnsafeMPMCQueue.TryPeek <T>(m_inner, out result));
 }