graph.h 1.36 KB
/* Graph routines */

#ifndef __GRAPH
#define __GRAPH

#include "list.h"

typedef struct sNode {
	void *pContent;
	tList OutEdges;
	tList InEdges;
	int bMark;
} tNode;

typedef struct sEdge {
	tNode *pSrc;
	tNode *pDest;
} tEdge;

typedef struct sGraph {
	tList Nodes;
	tList Edges;
} tGraph;

void Graph_Init(tGraph *pGraph);
tList *Graph_GetNodes(tGraph *pGraph);
tList *Graph_GetEdges(tGraph *pGraph);
int Graph_GetNumNodes(tGraph *pGraph);
int Graph_GetNumEdges(tGraph *pGraph);
tNode *Graph_AddNode(tGraph *pGraph, void *pContent);
tEdge *Graph_AddEdge(tGraph *pGraph, tNode *pSrc, tNode *pDest);
void Graph_RemoveEdge(tGraph *pGraph, tEdge *pEdge);
void Graph_UnmarkNodes(tGraph *pGraph);
int Graph_DepthFirstForward(tGraph *pGraph, tNode *pNode, tVisitFunc *pPreFunc, void *pPreArgs, tVisitFunc *pPostFunc, void *pPostArgs);
int Graph_DepthFirstBackward(tGraph *pGraph, tNode *pNode, tVisitFunc *pPreFunc, void *pPreArgs, tVisitFunc *pPostFunc, void *pPostArgs);
tNode *Graph_FindNode(tGraph *pGraph, void *pContent);
void Graph_CalcSccListList(tGraph *pGraph, tList *pListList);
void *Node_GetContent(tNode *pNode);
tList *Node_GetOutEdges(tNode *pNode);
tList *Node_GetInEdges(tNode *pNode);
int Node_GetOutDegree(tNode *pNode);
int Node_GetInDegree(tNode *pNode);
int Node_IsMarked(tNode *pNode);
tNode *Edge_GetSrcNode(tEdge *pEdge);
tNode *Edge_GetDestNode(tEdge *pEdge);

#endif