LGraph

Description Graph data structure
Header file LGraph.h
Author Stefano Emiliozzi, Camil Demetrescu
Created Jan 16, 2003
Last updated Sep 27, 2003

 

Contents


Introduction

The component LGraph provides support for representing directed and undirected graphs. It maintains only the topological information of a graph, keeping track of the links between nodes; adding information to edges and nodes is possible using others components such as LEdgeInfo and LNodeInfo.


Interface

Constants

LGraph_ID
LGraph_NODE_NOT_IN_GRAPH
LGraph_EDGE_NOT_IN_GRAPH
LGraph_DIRECTED
LGraph_UNDIRECTED

Types

LGraph
LGraph_TNode
LGraph_TEdge

Functions

LGraph*       LGraph_New           (Bool inDirected);
void          LGraph_Delete        (LGraph** AThis);
LGraph_TNode* LGraph_NewNode       (LGraph* This);
void          LGraph_DelNode       (LGraph* This, LGraph_TNode* inNode);
LGraph_TEdge* LGraph_NewEdge       (LGraph* This, LGraph_TNode* inSource, LGraph_TNode* inTarget);
void          LGraph_DelEdge       (LGraph* This, LGraph_TEdge* inEdge);
LGraph_TNode* LGraph_GetFirstNode  (LGraph* This);
LGraph_TNode* LGraph_GetLastNode   (LGraph* This);
LGraph_TEdge* LGraph_GetFirstEdge  (LGraph* This);
LGraph_TEdge* LGraph_GetLastEdge   (LGraph* This);
LArray*       LGraph_GetAllNodes   (LGraph* This);
LArray*       LGraph_GetAllEdges   (LGraph* This);
LArray*       LGraph_GetOutEdges   (LGraph* This, LGraph_TNode* inNode);
LArray*       LGraph_GetInEdges    (LGraph* This, LGraph_TNode* inNode);
LArray*       LGraph_GetAdjNodes   (LGraph* This, LGraph_TNode* inNode);
ui4           LGraph_GetOutDeg     (LGraph_TNode* inNode);
ui4           LGraph_GetInDeg      (LGraph_TNode* inNode);
ui4           LGraph_GetDegree     (LGraph_TNode* inNode);
ui4           LGraph_GetNodesCount (LGraph* This);
ui4           LGraph_GetEdgesCount (LGraph* This);
Bool          LGraph_IsDirected    (LGraph* This);
Bool          LGraph_IsEmpty       (LGraph* This);
ui4           LGraph_GetUsedMem    (LGraph* This);
void          LGraph_SetDebug      (LGraph* This, Bool inDebug);
void          LGraph_Dump          (LGraph* This);

Macros

LGraph_GetNodeIndex    (LGraph_TNode* inNode)
LGraph_GetEdgeIndex    (LGraph_TEdge* inEdge)
LGraph_GetNextNode     (LGraph_TNode* inNode)
LGraph_ForAllNodes     (LGraph* This, LGraph_TNode* thruNode)
LGraph_GetNextEdge     (LGraph_TEdge* inEdge)
LGraph_ForAllEdges     (LGraph* This, LGraph_TEdge* thruEdge)
LGraph_GetSource       (LGraph_TEdge* inEdge)
LGraph_GetTarget       (LGraph_TEdge* inEdge)
LGraph_GetFirstOutEdge (LGraph_TNode* inNode)
LGraph_GetNextOutEdge  (LGraph_TNode* inNode, LGraph_TEdge* inEdge)
LGraph_ForAllOut       (LGraph_TNode* inNode, LGraph_TEdge* thruEdge)
LGraph_GetFirstInEdge  (LGraph_TNode* inNode)
LGraph_GetNextInEdge   (LGraph_TNode* inNode, LGraph_TEdge* inEdge)
LGraph_ForAllIn        (LGraph_TNode* inNode, LGraph_TEdge* thruEdge)


API Reference

Macro Arguments Description
GetNodeIndex LGraph_TNode* inNode Returns a unique numerical ID in the range [0,n] associated to node inNode, where n is the number of nodes in the graph that contains inNode. This ID is the index of inNode in the LArray returned by GetAllNodes.
Important notice
: IDs returned by GetNodeIndex are reliable only if the set of nodes is not further changed by adding or removing nodes.
GetEdgeIndex LGraph_TEdge* inEdge Returns a unique numerical ID in the range [0,m] associated to edge inEdge, where m is the number of edges in the graph that contains inEdge. This ID is the index of inEdge in the LArray returned by GetAllEdges.
Important notice
: IDs returned by GetEdgeIndex are reliable only if the set of edges is not further changed by adding or removing edges.
GetNextNode
LGraph_TNode* inNode Returns the node that follows inNode in the list of nodes of the graph, or NULL if no such node exists. Useful to scan all nodes in the graph: see also GetFirstNode and ForAllNodes.
ForAllNodes
LGraph* This, LGraph_TNode* thruNode Cycles through the nodes of graph This. thruNode will contain at each iteration the currently scanned node.
Important notice
: node thruNode must not be deleted during the loop.
GetNextEdge
LGraph_TEdge* inEdge Returns the edge that follows inEdge in the list of edges of the graph, or NULL if no such edge exists. Useful to scan all edges in the graph: see also GetFirstEdge and ForAllEdges.
ForAllEdges
LGraph* This, LGraph_TEdge* thruEdge Cycles through the edges of graph This. thruEdge will contain at each iteration the currently scanned edge.
Important notice
: edge thruEdge must not be deleted during the loop.
GetSource
LGraph_TEdge* inEdge Returns the source node of edge inEdge.
GetTarget
LGraph_TEdge* inEdge Returns the target node of edge inEdge.
GetFirstOutEdge
LGraph_TNode* inNode Returns the first edge in the out-list of node inNode, or NULL if no such edge exists.
GetNextOutEdge
LGraph_TNode* inNode, LGraph_TEdge* inEdge Returns the edge that follows inEdge in the out-list of node inNode, or NULL if no such edge exists. The macro assumes that inNode is an endpoint of inEdge.
ForAllOut
LGraph_TNode* inNode, LGraph_TEdge* thruEdge Cycles through the edges in the out-list of node inNode. thruEdge will contain at each iteration the currently scanned edge.
Important notice
: edge thruEdge must not be deleted during the loop.
GetFirstInEdge
LGraph_TNode* inNode Returns the first edge in the in-list of node inNode, or NULL if no such edge exists.
GetNextInEdge
LGraph_TNode* inNode, LGraph_TEdge* inEdge Returns the edge that follows inEdge in the in-list of node inNode, or NULL if no such edge exists. The macro assumes that inNode is an endpoint of inEdge.
ForAllIn
LGraph_TNode* inNode, LGraph_TEdge* thruEdge Cycles through the edges in the in-list of node inNode. thruEdge will contain at each iteration the currently scanned edge. This macro can be used only in case of directed graphs.
Important notice
: edge thruEdge must not be deleted during the loop.

Function Arguments Description Returns Throws
New Bool inDirected Creates a new directed or undirected graph. Caller is responsible of dellocating the created object using LGraph_Delete. LGraph*
pointer to the newly created object.
-
Delete LGraph** ThisA Releases object *ThisA. *ThisA is set to NULL. void -
NewNode LGraph* This Adds a new node in the graph and returns a pointer to it. LGraph_TNode* -
DelNode
LGraph*       This
LGraph_TNode* inNode
Deletes the node inNode and all the edges incident to it from the graph. void NODE_IS_NOT_IN_GRAPH
if inNode isn't in the graph
NewEdge
LGraph*       This
LGraph_TNode* inSource
LGraph_TNode* inTarget
Adds an edge between inSource and inTarget and returns a pointer to it. LGraph_TEdge* NODE_IS_NOT_IN_GRAPH
if inSource or inTarget are not in the graph
DelEdge
LGraph*       This
LGraph_TNode* inEdge
Removes inEdge from the graph. void EDGE_IS_NOT_IN_GRAPH
if inEdge isn't in the graph
GetFirstNode LGraph* This Returns the first node in the graph. LGraph_TNode* -
GetLastNode LGraph* This Returns the last node in the graph. LGraph_TNode* -
GetFirstEdge LGraph* This Returns the first edge in the graph. LGraph_TEdge* -
GetLastEdge LGraph* This Returns the last edge in the graph. LGraph_TEdge* -
GetAllNodes LGraph* This Returns a LArray with all nodes in the graph. Caller is responsible of dellocating the created object using LArray_Delete. LArray* -
GetAllEdges LGraph* This Returns a LArray with all edges in the graph. Caller is responsible of dellocating the created object using LArray_Delete. LArray* -
GetOutEdges
LGraph*       This
LGraph_TNode* inNode
Returns a new LArray object containing all the outgoing edges of a given node. Caller is responsible of dellocating the created object using LArray_Delete. LArray* NODE_IS_NOT_IN_GRAPH
if inEdge isn't in the graph
GetInEdges
LGraph*       This
LGraph_TNode* inNode
Returns a new LArray object containing all the ingoing edges of a given node. It the graph is undirected, returns NULL. Caller is responsible of dellocating the created object using LArray_Delete. LArray* NODE_IS_NOT_IN_GRAPH
if inEdge isn't in the graph
GetAdjEdges
LGraph*       This
LGraph_TNode* inNode
Returns a new LArray object containing all the nodes adjacent to a given node. Caller is responsible of dellocating the created object using LArray_Delete. LArray* NODE_IS_NOT_IN_GRAPH
if inEdge isn't in the graph
IsDirected LGraph* This Returns TRUE if the graph is directed, FALSE otherwise. Bool -
IsEmpty LGraph* This Returns TRUE if the graph is empty, FALSE otherwise. Bool -
GetUsedMem LGraph* This Returns the memory usage in bytes of object This. ui4 -
GetInDeg
LGraph*       This
LGraph_TNode* inNode
Returns the in-degree of node inNode. If the graph is undirected this is 0. ui4 NODE_IS_NOT_IN_GRAPH
if inEdge isn't in the graph
GetOutDeg
LGraph*       This
LGraph_TNode* inNode
Returns the out-degree of node inNode. ui4 NODE_IS_NOT_IN_GRAPH
if inEdge isn't in the graph
GetDegree
LGraph*       This
LGraph_TNode* inNode
Returns the degree of node inNode (equal to GetInDeg(This, inNode) + GetOutDeg(This, inNode) ). ui4 NODE_IS_NOT_IN_GRAPH
if inEdge isn't in the graph
GetNodesCount LGraph* This Returns the number of nodes in the graph. ui4 -
GetEdgesCount LGraph* This Returns the number of edges in the graph. ui4 -


Revision history