Graphviz  2.41.20171026.1811
stack.c
Go to the documentation of this file.
1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 
15 #include "stack.h"
16 #include "circular.h"
17 #include <assert.h>
18 
20 {
21  nstack_t *s;
22 
23  s = NEW(nstack_t);
24 
25  s->top = NULL;
26  s->sz = 0;
27  return s;
28 }
29 
31 {
32  free(s);
33 }
34 
36 {
37  SET_ONSTACK(n);
38  NEXT(n) = s->top;
39  s->top = n;
40  s->sz += 1;
41 }
42 
44 {
45  Agnode_t *top = s->top;
46 
47  if (top) {
48  assert(s->sz > 0);
49  UNSET_ONSTACK(top);
50  s->top = NEXT(top);
51  s->sz -= 1;
52  } else {
53  assert(0);
54  }
55 
56  return top;
57 }
58 
60 {
61  return s->sz;
62 }
63 
64 /* stackCheck:
65  * Return true if n in on the stack.
66  */
68 {
69  return ONSTACK(n);
70 #ifdef OLD
71  stackitem_t *top = s->top;
72  Agnode_t *node;
73 
74  while (top != NULL) {
75  node = top->data;
76  if (node == n)
77  return 1;
78  top = top->next;
79  }
80 
81  return 0;
82 #endif
83 }
84 
85 #ifdef DEBUG
86 void printStack(nstack_t * s)
87 {
88  Agnode_t *n;
89  for (n = s->top; n; n = NEXT(n))
90  fprintf(stderr, " %s", n->name);
91  fprintf(stderr, "\n");
92 
93 }
94 #endif
#define ONSTACK(n)
Definition: circular.h:110
Definition: stack.h:23
#define SET_ONSTACK(n)
Definition: circular.h:116
void stackPush(nstack_t *s, Agnode_t *n)
Definition: stack.c:35
#define assert(x)
Definition: cghdr.h:47
#define NEXT(n)
Definition: circular.h:91
void freeStack(nstack_t *s)
Definition: stack.c:30
Agnode_t * stackPop(nstack_t *s)
Definition: stack.c:43
Definition: grammar.c:79
int stackCheck(nstack_t *s, Agnode_t *n)
Definition: stack.c:67
int stackSize(nstack_t *s)
Definition: stack.c:59
nstack_t * mkStack()
Definition: stack.c:19
#define NULL
Definition: logic.h:39
#define top(sp)
Definition: stack.h:35
Agnode_t * node(Agraph_t *g, char *name)
Definition: gv.cpp:103
Agnode_t * top
Definition: stack.h:24
#define UNSET_ONSTACK(n)
Definition: circular.h:122
int sz
Definition: stack.h:25
#define NEW(t)
Definition: memory.h:35