/*1Planarity-Related Graph Algorithms Project2Copyright (c) 1997-2010, John M. Boyer3All rights reserved. Includes a reference implementation of the following:45* John M. Boyer. "Simplified O(n) Algorithms for Planar Graph Embedding,6Kuratowski Subgraph Isolation, and Related Problems". Ph.D. Dissertation,7University of Victoria, 2001.89* John M. Boyer and Wendy J. Myrvold. "On the Cutting Edge: Simplified O(n)10Planarity by Edge Addition". Journal of Graph Algorithms and Applications,11Vol. 8, No. 3, pp. 241-273, 2004.1213* John M. Boyer. "A New Method for Efficiently Generating Planar Graph14Visibility Representations". In P. Eades and P. Healy, editors,15Proceedings of the 13th International Conference on Graph Drawing 2005,16Lecture Notes Comput. Sci., Volume 3843, pp. 508-511, Springer-Verlag, 2006.1718Redistribution and use in source and binary forms, with or without modification,19are permitted provided that the following conditions are met:2021* Redistributions of source code must retain the above copyright notice, this22list of conditions and the following disclaimer.2324* Redistributions in binary form must reproduce the above copyright notice, this25list of conditions and the following disclaimer in the documentation and/or26other materials provided with the distribution.2728* Neither the name of the Planarity-Related Graph Algorithms Project nor the names29of its contributors may be used to endorse or promote products derived from this30software without specific prior written permission.3132THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"33AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE34IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE35DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR36ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES37(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;38LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON39ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT40(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS41SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.42*/4344#ifndef _LISTCOLL_H45#define _LISTCOLL_H4647#ifdef __cplusplus48extern "C" {49#endif5051/* This include is needed for memset and memcpy */52#include <string.h>5354typedef struct55{56int prev, next;57} lcnode;5859typedef struct60{61int N;62lcnode *List;63} listCollectionRec;6465typedef listCollectionRec * listCollectionP;6667listCollectionP LCNew(int N);68void LCFree(listCollectionP *pListColl);6970void LCInsertAfter(listCollectionP listColl, int theAnchor, int theNewNode);71void LCInsertBefore(listCollectionP listColl, int theAnchor, int theNewNode);7273#ifndef SPEED_MACROS7475void LCReset(listCollectionP listColl);76void LCCopy(listCollectionP dst, listCollectionP src);7778int LCGetNext(listCollectionP listColl, int theList, int theNode);79int LCGetPrev(listCollectionP listColl, int theList, int theNode);8081int LCPrepend(listCollectionP listColl, int theList, int theNode);82int LCAppend(listCollectionP listColl, int theList, int theNode);83int LCDelete(listCollectionP listColl, int theList, int theNode);8485#else8687/* void LCReset(listCollectionP listColl); */8889#define LCReset(listColl) memset(listColl->List, NIL_CHAR, listColl->N*sizeof(lcnode))9091/* void LCCopy(listCollectionP dst, listCollectionP src) */9293#define LCCopy(dst, src) memcpy(dst->List, src->List, src->N*sizeof(lcnode))9495/* int LCGetNext(listCollectionP listColl, int theList, int theNode);96Return theNode's successor, unless it is theList head pointer */9798#define LCGetNext(listColl, theList, theNode) listColl->List[theNode].next==theList ? NIL : listColl->List[theNode].next99100/* int LCGetPrev(listCollectionP listColl, int theList, int theNode);101Return theNode's predecessor unless theNode is theList head.102To start going backwards, use NIL for theNode, which returns theList head's predecessor103Usage: Obtain last node, loop while NIL not returned, process node then get predecessor.104After theList head processed, get predecessor returns NIL because we started with105theList head's predecessor. */106107#define LCGetPrev(listColl, theList, theNode) \108(theNode==NIL \109? listColl->List[theList].prev \110: theNode==theList ? NIL : listColl->List[theNode].prev)111112/* int LCPrepend(listCollectionP listColl, int theList, int theNode);113After an append, theNode is last, which in a circular list is the direct predecessor114of the list head node, so we just back up one. For singletons, this has no effect.*/115116#define LCPrepend(listColl, theList, theNode) listColl->List[LCAppend(listColl, theList, theNode)].prev117118/* int LCAppend(listCollectionP listColl, int theList, int theNode);119If theList is empty, then theNode becomes its only member and is returned.120Otherwise, theNode is placed before theList head, which is returned. */121122#define LCAppend(listColl, theList, theNode) \123(theList==NIL \124? (listColl->List[theNode].prev = listColl->List[theNode].next = theNode) \125: (listColl->List[theNode].next = theList, \126listColl->List[theNode].prev = listColl->List[theList].prev, \127listColl->List[listColl->List[theNode].prev].next = theNode, \128listColl->List[theList].prev = theNode, \129theList))130131/* int LCDelete(listCollectionP listColl, int theList, int theNode);132If theList contains only one node, then NIL it out and return NIL meaning empty list133Otherwise, join the predecessor and successor, then134return either the list head or its successor if the deleted node is the list head135(in that case, the caller makes the successor become the new list head).*/136137138#define LCDelete(listColl, theList, theNode) \139listColl->List[theList].next == theList \140? (listColl->List[theList].prev = listColl->List[theList].next = NIL) \141: (listColl->List[listColl->List[theNode].prev].next = listColl->List[theNode].next, \142listColl->List[listColl->List[theNode].next].prev = listColl->List[theNode].prev, \143(theList==theNode ? listColl->List[theNode].next : theList))144145#endif146147#ifdef __cplusplus148}149#endif150151#endif152153154