/*
   File:        iqueue.h
   Author:      Dan Pelleg
   Created:     Tue Aug 21 18:40:07 EDT 2001
   Description: a simple bounded, cyclic, integer queue

   $Id: iqueue.h,v 1.2 2003/12/24 18:52:56 pgunn Exp $

   Copyright 2001, Dan Pelleg
*/

#ifndef IQUEUE_H
#define IQUEUE_H

#include "standard.h"
#include "ambs.h"
#include "amiv.h"

/* We simply use an ivec to store the elements. New enqueus can wrap
   around and back to the beginning.
*/

typedef struct {
  ivec *q;
  int nelems;                   /* the number of elements in the queue */
  int next_pos;                 /* the position "one after" the youngest key
                                   This is the position we'll enqueue into next */
  int size;                     /* the maximum #elems in the queue */
} iqueue;

iqueue* mk_empty_iqueue(int maxelems);

void free_iqueue(iqueue *);

/* enqueue the key i; if the queue is full retrn FALSE, TRUE
   otherwise */
bool ienqueue(iqueue *q, int key);

/* dequeue and return the key.
   It is an error to call idequeue if is_empty(q)
*/
int idequeue(iqueue *q);

/* tells you if theren's nothing in the queue */
bool iqueue_is_empty(const iqueue *q);

void fprintf_iqueue(FILE* fp, const char* m1, const iqueue *iq, const char* m2);

#endif /* IQUEUE_H */
