Fixed size queue which automatically dequeues old values upon new enqueues

I would write a wrapper class that on Enqueue would check the Count and then Dequeue when the count exceeds the limit. public class FixedSizedQueue<T> { readonly ConcurrentQueue<T> q = new ConcurrentQueue<T>(); private object lockObject = new object(); public int Limit { get; set; } public void Enqueue(T obj) { q.Enqueue(obj); lock (lockObject) { T … Read more

FIFO class in Java

You’re looking for any class that implements the Queue interface, excluding PriorityQueue and PriorityBlockingQueue, which do not use a FIFO algorithm. Probably a LinkedList using add (adds one to the end) and removeFirst (removes one from the front and returns it) is the easiest one to use. For example, here’s a program that uses a … Read more

Is there a queue implementation?

In fact, if what you want is a basic and easy to use fifo queue, slice provides all you need. queue := make([]int, 0) // Push to the queue queue = append(queue, 1) // Top (just get next element, don’t remove it) x = queue[0] // Discard top element queue = queue[1:] // Is empty … Read more

tech