private static void SplitRingBuffer(UnsafeRingBuffer *q) { //Wrap tail back to 0 for (int i = 0; i < 5; i++) { UnsafeRingBuffer.Push(q, 111); } //First half for (int i = 0; i < 5; i++) { UnsafeRingBuffer.Push(q, i); } //Move head by 5 for (int i = 0; i < 5; i++) { UnsafeRingBuffer.Pop <int>(q, out _); } //Second half (head and tail are now both 5) for (int i = 5; i < 10; i++) { UnsafeRingBuffer.Push(q, i); } //Circular buffer now "ends" in the middle of the underlying array }
public void InvalidTypeTest() { var q = UnsafeRingBuffer.Allocate <int>(10); Assert.Catch <AssertException>(() => { UnsafeRingBuffer.Push <float>(q, 162); }); UnsafeRingBuffer.Free(q); }
public void DequeueTest() { var q = UnsafeRingBuffer.Allocate <int>(10); for (int i = 0; i < 10; i++) { UnsafeRingBuffer.Push(q, i * i); } for (int i = 0; i < 10; i++) { UnsafeRingBuffer.Pop <int>(q, out int num); Assert.AreEqual(i * i, num); } UnsafeRingBuffer.Free(q); }
public void PushTest() { var q = UnsafeRingBuffer.Allocate <int>(10); for (int i = 0; i < 10; i++) { UnsafeRingBuffer.Push(q, i * i); } Assert.AreEqual(10, UnsafeRingBuffer.GetCount(q)); Assert.AreEqual(10, UnsafeRingBuffer.GetCapacity(q)); UnsafeRingBuffer.Clear(q); Assert.AreEqual(0, UnsafeRingBuffer.GetCount(q)); Assert.AreEqual(10, UnsafeRingBuffer.GetCapacity(q)); UnsafeRingBuffer.Free(q); }
public void PeekTest() { var q = UnsafeRingBuffer.Allocate <int>(10); for (int i = 0; i < 10; i++) { UnsafeRingBuffer.Push(q, (int)Math.Pow(i + 2, 2)); } for (int i = 0; i < 10; i++) { UnsafeRingBuffer.Peek <int>(q, out int num); Assert.AreEqual(4, num); } //Verify no items are dequeued Assert.AreEqual(10, UnsafeRingBuffer.GetCount(q)); UnsafeRingBuffer.Free(q); }
public bool Push(T item) { return(UnsafeRingBuffer.Push(m_inner, item)); }