/* This program is due to R. Strandh, and has been modified by O. Baudon O. Baudon, project GML, February 23, 1994 Copyright (c) 1996 - LaBRI, Universite Bordeaux 1. All rights reserved. See the file "license.terms" for information on usage and redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. Purpose: Generalized queue (well, list) package. */ #ifndef GQUEUE_H #define GQUEUE_H #ifndef NO_STDLIB_H #include #else #include "compat/stdlib.h" #endif extern void * (* gq_malloc)(size_t size); extern void (* gq_free)(void * p); typedef struct gqueue_structure *gqueue; /* The queue uses the concept of a cursor. A cursor works like the emacs dot, i.e. it is located between two element, before the first element, or after the last element. Every queue has a cursor stack. The top of the stack is the cursor used by the queue operations. We call it the current cursor. */ /* create an empty queue */ extern gqueue gq_create(void); /* check whether queue is empty */ extern int gq_empty(gqueue); /* destroy the queue */ extern void gq_destroy(gqueue); /* set the destroy function for individual elements */ extern void gq_set_destroy(gqueue, void (*)()); /* functions to position the current cursor */ /* position current cursor before the first element */ extern void gq_go_beginning(gqueue); /* position current cursor after the last element */ extern void gq_go_end(gqueue); /* move current cursor forward */ extern void gq_go_forward(gqueue); /* move current cursor backward */ extern void gq_go_backward(gqueue); /* functions for checking where the current cursor is located */ /* check if current cursor is located before the first element */ extern int gq_at_beginning(gqueue); /* check if current cursor is located after the last element */ extern int gq_at_end(gqueue); /* get element after current cursor without moving current cursor */ extern void *gq_get(gqueue); /* get first element of queue without moving current cursor */ extern void *gq_get_first(gqueue); /* functions for insertion and deletion of elements */ /* insert an element after current cursor and position the current cursor after the newly inserted element */ extern void gq_insert(gqueue, void *); /* delete element after the current cursor */ extern void gq_delete(gqueue); /* replace the element after the current cursor */ extern void gq_replace(gqueue, void *); /* functions for manipulating the cursor stack */ /* push old cursor and create a new current cursor with undefined value */ extern void gq_push_cursor(gqueue); /* pop the cursor stack replacing the current cursor with value pushed */ extern void gq_pop_cursor(gqueue); /* functions to use a gqueue like a set of pointers. These functions do not affect the cursor. */ extern gqueue gq_copy(gqueue); extern void gq_make_empty(gqueue q); extern int gq_member(gqueue q, void *elem); /* Add an element iff it does not yet belong to the gqueue. */ extern void gq_add(gqueue q, void *elem); /* Subtract an element from the queue if it exists. */ extern void gq_subtract(gqueue q, void *elem); extern void gq_union(gqueue q, gqueue r); extern void gq_intersection(gqueue q, gqueue r); extern void gq_concat(gqueue q, gqueue r); extern int gq_size(gqueue q); #endif