Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/graphs/planarity/stack.h
4057 views
1
/*
2
Planarity-Related Graph Algorithms Project
3
Copyright (c) 1997-2010, John M. Boyer
4
All rights reserved. Includes a reference implementation of the following:
5
6
* John M. Boyer. "Simplified O(n) Algorithms for Planar Graph Embedding,
7
Kuratowski Subgraph Isolation, and Related Problems". Ph.D. Dissertation,
8
University of Victoria, 2001.
9
10
* John M. Boyer and Wendy J. Myrvold. "On the Cutting Edge: Simplified O(n)
11
Planarity by Edge Addition". Journal of Graph Algorithms and Applications,
12
Vol. 8, No. 3, pp. 241-273, 2004.
13
14
* John M. Boyer. "A New Method for Efficiently Generating Planar Graph
15
Visibility Representations". In P. Eades and P. Healy, editors,
16
Proceedings of the 13th International Conference on Graph Drawing 2005,
17
Lecture Notes Comput. Sci., Volume 3843, pp. 508-511, Springer-Verlag, 2006.
18
19
Redistribution and use in source and binary forms, with or without modification,
20
are permitted provided that the following conditions are met:
21
22
* Redistributions of source code must retain the above copyright notice, this
23
list of conditions and the following disclaimer.
24
25
* Redistributions in binary form must reproduce the above copyright notice, this
26
list of conditions and the following disclaimer in the documentation and/or
27
other materials provided with the distribution.
28
29
* Neither the name of the Planarity-Related Graph Algorithms Project nor the names
30
of its contributors may be used to endorse or promote products derived from this
31
software without specific prior written permission.
32
33
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
37
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
40
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
*/
44
45
#ifndef STACK_H
46
#define STACK_H
47
48
#ifdef __cplusplus
49
extern "C" {
50
#endif
51
52
// includes mem functions like memcpy
53
#include <string.h>
54
55
typedef struct
56
{
57
int *S;
58
int size, capacity;
59
} stack;
60
61
typedef stack * stackP;
62
63
stackP sp_New(int);
64
void sp_Free(stackP *);
65
66
int sp_Copy(stackP, stackP);
67
68
int sp_CopyContent(stackP stackDst, stackP stackSrc);
69
stackP sp_Duplicate(stackP theStack);
70
71
#define sp_GetCapacity(theStack) (theStack->capacity)
72
73
#ifndef SPEED_MACROS
74
75
int sp_ClearStack(stackP);
76
int sp_GetCurrentSize(stackP theStack);
77
int sp_SetCurrentSize(stackP theStack, int top);
78
79
int sp_IsEmpty(stackP);
80
int sp_NonEmpty(stackP);
81
82
#define sp_Push(theStack, a) { if (sp__Push(theStack, (a)) != OK) return NOTOK; }
83
#define sp_Push2(theStack, a, b) { if (sp__Push2(theStack, (a), (b)) != OK) return NOTOK; }
84
85
int sp__Push(stackP, int);
86
int sp__Push2(stackP, int, int);
87
88
#define sp_Pop(theStack, a) { if (sp__Pop(theStack, &(a)) != OK) return NOTOK; }
89
#define sp_Pop2(theStack, a, b) { if (sp__Pop2(theStack, &(a), &(b)) != OK) return NOTOK; }
90
91
int sp__Pop(stackP, int *);
92
int sp__Pop2(stackP, int *, int *);
93
94
int sp_Top(stackP);
95
int sp_Get(stackP, int);
96
int sp_Set(stackP, int, int);
97
98
#else
99
100
#define sp_ClearStack(theStack) theStack->size=0
101
#define sp_GetCurrentSize(theStack) (theStack->size)
102
#define sp_SetCurrentSize(theStack, Size) ((Size) > theStack->capacity ? NOTOK : (theStack->size = (Size), OK))
103
104
#define sp_IsEmpty(theStack) !theStack->size
105
#define sp_NonEmpty(theStack) theStack->size
106
107
#define sp_Push(theStack, a) theStack->S[theStack->size++] = a
108
#define sp_Push2(theStack, a, b) {sp_Push(theStack, a); sp_Push(theStack, b);}
109
110
#define sp_Pop(theStack, a) a=theStack->S[--theStack->size]
111
#define sp_Pop2(theStack, a, b) {sp_Pop(theStack, b);sp_Pop(theStack, a);}
112
113
#define sp_Top(theStack) (theStack->size ? theStack->S[theStack->size-1] : NIL)
114
#define sp_Get(theStack, pos) (theStack->S[pos])
115
#define sp_Set(theStack, pos, val) (theStack->S[pos] = val)
116
117
#endif
118
119
#ifdef __cplusplus
120
}
121
#endif
122
123
#endif
124
125