FIFO List/Queue

Hello

I've been search, without success, for a FIFO library/class. I've seen topics and code snippets, none of which were quite what I was looking for, or understandable :-/

Can anyone point me to a true and proven FIFO Queue?

I'm looking for a rather simple implementation:

  • to store long unsigned integers
  • Pop (oldest)
  • Push (newest)
  • Count
  • Empty
  • Peek (oldest, without poping)

Cheers!

Hi, I've built a simple event system around an "event queue" which is just that: a specialized fifo.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279102180

Look for the EventQueue class. It should be similar to what you need (needs to be adapted of course).

HTH

Wow! This is outstanding Mromani!

I've been checking your classes out, have run them, and am quite impressed.

They'll do an outstanding job for what I'm looking to do.

I may add a 'peekEvent' method to the events class, which won't actually dequeue the event. But other than that, they pretty well do the job!

Thanks again.

Ron

I'm glad you like the code :slight_smile:
I might add a peek method as soon as I have time or I'll include your own if you'll publish it.

I'll be glad to share my peek method.

I'm still deep in 'designing' my application for the moment. Once I've coded and tested the method, I'll post it!

Thanx

Implementation proposal for peek method.

// read the next-to-be-dequeued event from the queue;
// returns true if successful, false if the
// queue is empty (the parameteres are not touched
// in this case)
boolean EventQueue::peekEvent(int* ev_code, int* ev_param) {
  
  if (numEvents == 0) {
    return false;
  }

  eventQueueTail = (eventQueueTail + 1) % EVQUEUE_SIZE;

  // store event code and event parameter
  // into the user-supplied variables
  *ev_code = eventQueue[eventQueueTail];
  *ev_param = eventParam[eventQueueTail];

  // don't update the number of events in queue
  // since we're only reading the queue head
  //numEvents--;

  return true;
}

HTH