gqueue.h
#ifndef BGLIBS__GENERIC_QUEUE__H__
#define BGLIBS__GENERIC_QUEUE__H__
#include "adt_common.h"
struct gqueue_node
{
struct gqueue_node* next;
char data[0];
};
struct gqueue
{
struct gqueue_node* head;
struct gqueue_node* tail;
unsigned count;
};
int gqueue_push(struct gqueue* d, unsigned datasize, const void* data,
adt_copy_fn* fn);
void* gqueue_top(const struct gqueue* q);
void gqueue_pop(struct gqueue* q, adt_free_fn* fn);
#define GQUEUE_DECL(PREFIX,TYPE) \
extern int PREFIX##_push(struct gqueue* q, TYPE const* data); \
extern TYPE* PREFIX##_top(struct gqueue* q); \
extern void PREFIX##_pop(struct gqueue* q);
#define GQUEUE_PUSH_DEFN(PREFIX,TYPE,COPY) \
int PREFIX##_push(struct gqueue* q, TYPE const* data) { \
return gqueue_push(q, sizeof *data, data, (adt_copy_fn*)COPY); \
}
#define GQUEUE_TOP_DEFN(PREFIX,TYPE) \
TYPE* PREFIX##_top(struct gqueue* q) { \
return (q->head == 0) ? 0 : (TYPE*)q->head->data; \
}
#define GQUEUE_POP_DEFN(PREFIX,FREE) \
void PREFIX##_pop(struct gqueue* q) { \
gqueue_pop(q, (adt_free_fn*)(FREE)); \
}
#define GQUEUE_DEFN(PREFIX,TYPE,COPY,FREE) \
GQUEUE_PUSH_DEFN(PREFIX,TYPE,COPY) \
GQUEUE_TOP_DEFN(PREFIX,TYPE) \
GQUEUE_POP_DEFN(PREFIX,FREE)
#endif
gqueue_push
int gqueue_push(struct gqueue *d, unsigned datasize, const void *data, adt_copy_fn *fn)
Definition: gqueue_push.c:8
adt_free_fn
void adt_free_fn(void *)
Definition: adt_common.h:12
gqueue_pop
void gqueue_pop(struct gqueue *q, adt_free_fn *fn)
Definition: gqueue_pop.c:9
gqueue_node::next
struct gqueue_node * next
Definition: gqueue.h:23
gqueue_node
Definition: gqueue.h:20
gqueue_node::data
char data[0]
Definition: gqueue.h:25
gqueue
Definition: gqueue.h:29
gqueue_top
void * gqueue_top(const struct gqueue *q)
Definition: gqueue_top.c:5
gqueue::count
unsigned count
Definition: gqueue.h:36
gqueue::tail
struct gqueue_node * tail
Definition: gqueue.h:34
gqueue::head
struct gqueue_node * head
Definition: gqueue.h:32
adt_copy_fn
int adt_copy_fn(void *, const void *)
Definition: adt_common.h:16