public static void IEnumerable_Testing <TQueue>() where TQueue : IQueue <int>, new() { { // enqueue only int[] values = { 0, 1, 2, 3, 4, 5, }; IQueue <int> queue = new TQueue(); values.Stepper(i => queue.Enqueue(i)); #pragma warning disable CA1829 // Use Length/Count property instead of Count() when available Assert.IsTrue(System.Linq.Enumerable.Count(queue) == values.Length); #pragma warning restore CA1829 // Use Length/Count property instead of Count() when available ISet <int> set = SetHashLinked.New <int>(); values.Stepper(i => set.Add(i)); foreach (int i in queue) { Assert.IsTrue(set.Contains(i)); set.Remove(i); } Assert.IsTrue(set.Count == 0); } { // enqueue + dequeue int[] values = { 0, 1, 2, 3, 4, 5, }; int[] expectedValues = { 2, 3, 4, 5, }; IQueue <int> queue = new TQueue(); values.Stepper(i => queue.Enqueue(i)); queue.Dequeue(); queue.Dequeue(); #pragma warning disable CA1829 // Use Length/Count property instead of Count() when available Assert.IsTrue(System.Linq.Enumerable.Count(queue) == expectedValues.Length); #pragma warning restore CA1829 // Use Length/Count property instead of Count() when available ISet <int> set = SetHashLinked.New <int>(); expectedValues.Stepper(i => set.Add(i)); foreach (int i in queue) { Assert.IsTrue(set.Contains(i)); set.Remove(i); } Assert.IsTrue(set.Count == 0); } { // enqueue + dequeue int[] values = { 0, 1, 2, 3, 4, 5, }; IQueue <int> queue = new TQueue(); values.Stepper(i => queue.Enqueue(i)); values.Stepper(i => { queue.Dequeue(); queue.Enqueue(i); }); #pragma warning disable CA1829 // Use Length/Count property instead of Count() when available Assert.IsTrue(System.Linq.Enumerable.Count(queue) == values.Length); #pragma warning restore CA1829 // Use Length/Count property instead of Count() when available ISet <int> set = SetHashLinked.New <int>(); values.Stepper(i => set.Add(i)); foreach (int i in queue) { Assert.IsTrue(set.Contains(i)); set.Remove(i); } Assert.IsTrue(set.Count == 0); } }
public static void Stepper_Testing <TQueue>() where TQueue : IQueue <int>, new() { { // enqueue only int[] values = { 0, 1, 2, 3, 4, 5, }; IQueue <int> queue = new TQueue(); values.Stepper(i => queue.Enqueue(i)); Assert.IsTrue(queue.Count == values.Length); ISet <int> set = SetHashLinked.New <int>(); values.Stepper(i => set.Add(i)); queue.Stepper(i => { Assert.IsTrue(set.Contains(i)); set.Remove(i); }); Assert.IsTrue(set.Count == 0); } { // enqueue + dequeue int[] values = { 0, 1, 2, 3, 4, 5, }; int[] expectedValues = { 2, 3, 4, 5, }; IQueue <int> queue = new TQueue(); values.Stepper(i => queue.Enqueue(i)); queue.Dequeue(); queue.Dequeue(); Assert.IsTrue(queue.Count == expectedValues.Length); ISet <int> set = SetHashLinked.New <int>(); expectedValues.Stepper(i => set.Add(i)); queue.Stepper(i => { Assert.IsTrue(set.Contains(i)); set.Remove(i); }); Assert.IsTrue(set.Count == 0); } { // enqueue + dequeue int[] values = { 0, 1, 2, 3, 4, 5, }; IQueue <int> queue = new TQueue(); values.Stepper(i => queue.Enqueue(i)); values.Stepper(i => { queue.Dequeue(); queue.Enqueue(i); }); Assert.IsTrue(queue.Count == values.Length); ISet <int> set = SetHashLinked.New <int>(); values.Stepper(i => set.Add(i)); queue.Stepper(i => { Assert.IsTrue(set.Contains(i)); set.Remove(i); }); Assert.IsTrue(set.Count == 0); } }
/// <summary> /// Invoke any actions that may have accumulated. /// </summary> private void Update() { while (actionQueue.Count > 0) { actionQueue.Dequeue()(); } }
public ChunkBatch GetBatchOfChunksToProcess() { if (m_ChunkBatches.Count == 0) { return(null); } return(m_ChunkBatches.Dequeue()); }
public Chunk GetFinishedChunk() { if (FinishedChunks.Count == 0) { return(null); } return(FinishedChunks.Dequeue()); }
private static List <Chunk> DequeueChunks(TQueue <Chunk> queue) { List <Chunk> chunks = new List <Chunk>(); while (queue.Count > 0) { chunks.Add(queue.Dequeue()); } return(chunks); }
private byte ReadNextByte() { if (recData.Count > 0) { byte c = recData.Dequeue(); System.Diagnostics.Debug.WriteLine(c); YmodeResponseGot?.Invoke((char)c + " "); return(c); } else { return(0xFF); // error } }
private static List <Chunk> GetChunksNotOnTheBorderInQueue(TQueue <Chunk> queue) { List <Chunk> chunks = new List <Chunk>(); while (queue.Count > 0) { Chunk chunk = queue.Dequeue(); if (!chunk.IsOnTheBorder) { chunks.Add(chunk); } } return(chunks); }
private static List<Chunk> GetChunksNotOnTheBorderInQueue(TQueue<Chunk> queue) { List<Chunk> chunks = new List<Chunk>(); while (queue.Count > 0) { Chunk chunk = queue.Dequeue(); if (!chunk.IsOnTheBorder) { chunks.Add(chunk); } } return chunks; }
private static List<Chunk> DequeueChunks(TQueue<Chunk> queue) { List<Chunk> chunks = new List<Chunk>(); while (queue.Count > 0) { chunks.Add(queue.Dequeue()); } return chunks; }
private string ReadLine() { if (!HasSource) { return(null); } try { string line = source.Dequeue(); line = line.TrimEnd((char)SpecialChars.CR, (char)SpecialChars.LF); if (line.Contains("\r\n")) { return(ReadLine()); } return(line); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); return(null); } /* * StringBuilder line = new StringBuilder(); * int c = -1; * while (true) * { * if (ShouldStop) * { * break; * } * c = source.ReadByte(); * if (c < 0) * { * * if (line.Length <= 0) * { * * return null; * * } * break; * * } * if ((c == (int)SpecialChars.LF) || (c == (int)SpecialChars.CR)) || { || || if (line.Length <= 0) || { || || continue; || || } || break; || || } || line.Append((char)c); || ||} ||//System.Diagnostics.Debug.WriteLine(count.ToString() + ": " + line.ToString()); ||return line.ToString();*/ }