/* author: R. Strandh. (slightly modified by O. Baudon, D. Sherman and others) 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 _GQ_PACKAGE_ #define _GQ_PACKAGE_ 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. */ /***********************************************************/ /* general functions */ /* create an empty queue */ extern gqueue gq_create(void); /* check whether queue is empty */ extern int gq_empty(gqueue q); /* clone a gqueue */ extern gqueue gq_copy(gqueue q); /* destroy the queue */ extern void gq_destroy(gqueue q); /* remove all the elements from the queue */ extern void gq_make_empty(gqueue q); /* check whether an element is in the queue */ extern int gq_member(gqueue q, void *elem); /* apply a function to all the elements of the queue */ extern void gq_map(gqueue q, void (*fun)(void *)); /***********************************************************/ /* functions to position the current cursor */ /* position current cursor before the first element */ extern void gq_go_beginning(gqueue q); /* position current cursor after the last element */ extern void gq_go_end(gqueue q); /* move current cursor forward */ extern void gq_go_forward(gqueue q); /* move current cursor backward */ extern void gq_go_backward(gqueue q); /***********************************************************/ /* 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 q); /* check if current cursor is located after the last element */ extern int gq_at_end(gqueue q); /***********************************************************/ /* functions for getting an element from the queue */ /* get element after current cursor without moving current cursor */ extern void *gq_get(gqueue q); /* get first element of queue without moving current cursor */ extern void *gq_get_first(gqueue q); /***********************************************************/ /* 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 *elem); /* Add an element iff it does not already belong to the gqueue. */ extern void gq_add(gqueue q, void *elem); /* set the auxiliary function when deleting individual elements */ extern void gq_set_auxiliary_delete(gqueue q, void (*fun)(void *)); /* delete element after the current cursor */ extern void gq_delete(gqueue q); /* Subtract an element from the queue if it exists. */ extern void gq_subtract(gqueue q, void *elem); /* replace the element after the current cursor */ extern void gq_replace(gqueue, void *elem); /*********************************************************** /* functions for manipulating the cursor stack */ /* push old cursor and create a new current cursor with undefined value */ extern void gq_push_cursor(gqueue q); /* pop the cursor stack replacing the current cursor with value pushed */ extern void gq_pop_cursor(gqueue q); /*********************************************************** /* set operations on gqueue */ extern void gq_union(gqueue q, gqueue r); extern void gq_intersection(gqueue q, gqueue r); extern void gq_concat(gqueue q, gqueue r); #define _GQ_PACKAGE_ #endif _GQ_PACKAGE_