/misc/src/release/graphviz-2.18-1/src/graphviz-2.18/lib/circogen/stack.c

Go to the documentation of this file.
00001 /* $Id: stack.c,v 1.1.1.1 2004/12/23 04:04:31 ellson Exp $ $Revision: 1.1.1.1 $ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /**********************************************************
00005 *      This software is part of the graphviz package      *
00006 *                http://www.graphviz.org/                 *
00007 *                                                         *
00008 *            Copyright (c) 1994-2004 AT&T Corp.           *
00009 *                and is licensed under the                *
00010 *            Common Public License, Version 1.0           *
00011 *                      by AT&T Corp.                      *
00012 *                                                         *
00013 *        Information and Software Systems Research        *
00014 *              AT&T Research, Florham Park NJ             *
00015 **********************************************************/
00016 
00017 
00018 #include        "stack.h"
00019 #include        "circular.h"
00020 #include        <assert.h>
00021 
00022 nstack_t *mkStack()
00023 {
00024     nstack_t *s;
00025 
00026     s = NEW(nstack_t);
00027 
00028     s->top = NULL;
00029     s->sz = 0;
00030     return s;
00031 }
00032 
00033 void freeStack(nstack_t * s)
00034 {
00035     free(s);
00036 }
00037 
00038 void stackPush(nstack_t * s, Agnode_t * n)
00039 {
00040     SET_ONSTACK(n);
00041     NEXT(n) = s->top;
00042     s->top = n;
00043     s->sz += 1;
00044 }
00045 
00046 Agnode_t *stackPop(nstack_t * s)
00047 {
00048     Agnode_t *top = s->top;
00049 
00050     if (top) {
00051         assert(s->sz > 0);
00052         UNSET_ONSTACK(top);
00053         s->top = NEXT(top);
00054         s->sz -= 1;
00055     } else {
00056         assert(0);
00057     }
00058 
00059     return top;
00060 }
00061 
00062 int stackSize(nstack_t * s)
00063 {
00064     return s->sz;
00065 }
00066 
00067 /* stackCheck:
00068  * Return true if n in on the stack.
00069  */
00070 int stackCheck(nstack_t * s, Agnode_t * n)
00071 {
00072     return ONSTACK(n);
00073 #ifdef OLD
00074     stackitem_t *top = s->top;
00075     Agnode_t *node;
00076 
00077     while (top != NULL) {
00078         node = top->data;
00079         if (node == n)
00080             return 1;
00081         top = top->next;
00082     }
00083 
00084     return 0;
00085 #endif
00086 }
00087 
00088 #ifdef DEBUG
00089 void printStack(nstack_t * s)
00090 {
00091     Agnode_t *n;
00092     for (n = s->top; n; n = NEXT(n))
00093         fprintf(stderr, " %s", n->name);
00094     fprintf(stderr, "\n");
00095 
00096 }
00097 #endif

Generated on Mon Mar 31 19:03:23 2008 for Graphviz by  doxygen 1.5.1