Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/graphs/planarity/listcoll.h
4099 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 _LISTCOLL_H
46
#define _LISTCOLL_H
47
48
#ifdef __cplusplus
49
extern "C" {
50
#endif
51
52
/* This include is needed for memset and memcpy */
53
#include <string.h>
54
55
typedef struct
56
{
57
int prev, next;
58
} lcnode;
59
60
typedef struct
61
{
62
int N;
63
lcnode *List;
64
} listCollectionRec;
65
66
typedef listCollectionRec * listCollectionP;
67
68
listCollectionP LCNew(int N);
69
void LCFree(listCollectionP *pListColl);
70
71
void LCInsertAfter(listCollectionP listColl, int theAnchor, int theNewNode);
72
void LCInsertBefore(listCollectionP listColl, int theAnchor, int theNewNode);
73
74
#ifndef SPEED_MACROS
75
76
void LCReset(listCollectionP listColl);
77
void LCCopy(listCollectionP dst, listCollectionP src);
78
79
int LCGetNext(listCollectionP listColl, int theList, int theNode);
80
int LCGetPrev(listCollectionP listColl, int theList, int theNode);
81
82
int LCPrepend(listCollectionP listColl, int theList, int theNode);
83
int LCAppend(listCollectionP listColl, int theList, int theNode);
84
int LCDelete(listCollectionP listColl, int theList, int theNode);
85
86
#else
87
88
/* void LCReset(listCollectionP listColl); */
89
90
#define LCReset(listColl) memset(listColl->List, NIL_CHAR, listColl->N*sizeof(lcnode))
91
92
/* void LCCopy(listCollectionP dst, listCollectionP src) */
93
94
#define LCCopy(dst, src) memcpy(dst->List, src->List, src->N*sizeof(lcnode))
95
96
/* int LCGetNext(listCollectionP listColl, int theList, int theNode);
97
Return theNode's successor, unless it is theList head pointer */
98
99
#define LCGetNext(listColl, theList, theNode) listColl->List[theNode].next==theList ? NIL : listColl->List[theNode].next
100
101
/* int LCGetPrev(listCollectionP listColl, int theList, int theNode);
102
Return theNode's predecessor unless theNode is theList head.
103
To start going backwards, use NIL for theNode, which returns theList head's predecessor
104
Usage: Obtain last node, loop while NIL not returned, process node then get predecessor.
105
After theList head processed, get predecessor returns NIL because we started with
106
theList head's predecessor. */
107
108
#define LCGetPrev(listColl, theList, theNode) \
109
(theNode==NIL \
110
? listColl->List[theList].prev \
111
: theNode==theList ? NIL : listColl->List[theNode].prev)
112
113
/* int LCPrepend(listCollectionP listColl, int theList, int theNode);
114
After an append, theNode is last, which in a circular list is the direct predecessor
115
of the list head node, so we just back up one. For singletons, this has no effect.*/
116
117
#define LCPrepend(listColl, theList, theNode) listColl->List[LCAppend(listColl, theList, theNode)].prev
118
119
/* int LCAppend(listCollectionP listColl, int theList, int theNode);
120
If theList is empty, then theNode becomes its only member and is returned.
121
Otherwise, theNode is placed before theList head, which is returned. */
122
123
#define LCAppend(listColl, theList, theNode) \
124
(theList==NIL \
125
? (listColl->List[theNode].prev = listColl->List[theNode].next = theNode) \
126
: (listColl->List[theNode].next = theList, \
127
listColl->List[theNode].prev = listColl->List[theList].prev, \
128
listColl->List[listColl->List[theNode].prev].next = theNode, \
129
listColl->List[theList].prev = theNode, \
130
theList))
131
132
/* int LCDelete(listCollectionP listColl, int theList, int theNode);
133
If theList contains only one node, then NIL it out and return NIL meaning empty list
134
Otherwise, join the predecessor and successor, then
135
return either the list head or its successor if the deleted node is the list head
136
(in that case, the caller makes the successor become the new list head).*/
137
138
139
#define LCDelete(listColl, theList, theNode) \
140
listColl->List[theList].next == theList \
141
? (listColl->List[theList].prev = listColl->List[theList].next = NIL) \
142
: (listColl->List[listColl->List[theNode].prev].next = listColl->List[theNode].next, \
143
listColl->List[listColl->List[theNode].next].prev = listColl->List[theNode].prev, \
144
(theList==theNode ? listColl->List[theNode].next : theList))
145
146
#endif
147
148
#ifdef __cplusplus
149
}
150
#endif
151
152
#endif
153
154