graph.h
Types | |
This type represents the abstract type for a graph. | |
This type is the abstract type for a node in a graph. | |
This type is the abstract type for an arc in a graph. | |
Functions | |
Returns a new graph with no nodes or arcs. | |
Frees the storage for the graph, along with its nodes and arcs. | |
Adds a node to the graph with the specified name. | |
Removes and frees the specified node from the graph, along with any arcs that enter or leave that node. | |
Returns the node in the graph that has the specified name. | |
Adds a new arc to the graph connecting nodes n1 and n2 . | |
Removes and frees the specified arc. | |
Returns true if there is an arc from n1 to n2 . | |
Returns a set consisting of all nodes in the graph. | |
getArcSet(node) | Returns a set consisting of all arcs, either in the graph or starting at the specified node. |
Returns a set consisting of the nodes to which a given node is connected. | |
Returns the name of the node. | |
Returns the node at the beginning of the specified arc. | |
Returns the node at the end of the specified arc. | |
Returns the "cost" associated with traversing an arc. | |
Sets the cost of traversing the arc. | |
Sets the comparison function used to order the nodes in a graph when they are enumerated. | |
Sets the comparison function used to order the arcs in a graph when they are enumerated. |
typedef struct GraphCDT *Graph;
Graph
consists of a set of nodes together with a
set of arcs. Each arc connects two nodes in one direction.
Undirected graphs must include two arcs for each bidirectional
connection.
typedef struct NodeCDT *Node;
getBlockData
and setBlockData
described
in cslib.h
.
typedef struct ArcCDT *Arc;
getBlockData
and setBlockData
described
in cslib.h
.
Graph newGraph(void);
Usage:
g = newGraph();
void freeGraph(Graph g);
Usage:
freeGraph(g);
Node addNode(Graph g, string name);
addNode
generates an error. The
function returns the Node
value.
Usage:
node = addNode(g, name);
void removeNode(Graph g, Node node);
Usage:
removeNode(g, node);
Node getNode(Graph g, string name);
getNode
returns NULL
.
Usage:
node = getNode(g, name);
Arc addArc(Graph g, Node n1, Node n2);
n1
and
n2
. The function returns the Arc
value.
Usage:
arc = addArc(g, n1, n2);
void removeArc(Graph g, Arc arc);
Usage:
removeArc(g, arc);
bool isConnected(Node n1, Node n2);
true
if there is an arc from n1
to n2
.
Usage:
if (isConnected(n1, n2)) . . .
Set getNodeSet(Graph g);
foreach
macro to initialize an iterator. For example, the following
idiom iterates over the nodes in the specified graph:
foreach (node in getNodeSet(g)) . . .
Usage:
nodeSet = getNodeSet(g);
Set getArcSet(void *arg);
foreach
macro to initialize an iterator. For
example, the following idiom iterates over the arcs in the specified
graph:
foreach (arc in getArcSet(g)) . . .
Usage:
arcSet = getArcSet(g); arcSet = getArcSet(node);
Set getNeighbors(Node node);
foreach
macro to initialize an iterator. For
example, the following idiom iterates over the nodes to which
the node start
is connected:
foreach (node in getNeighbors(start)) . . .
Usage:
nodeSet = getNeighbors(node);
string getName(Node node);
Usage:
str = getName(node);
Node startOfArc(Arc arc);
Usage:
node = startOfArc(arc);
Node endOfArc(Arc arc);
Usage:
node = endOfArc(arc);
double getCost(Arc arc);
Usage:
cost = getCost(arc);
void setCost(Arc arc, double cost);
Usage:
setCost(arc, cost);
void setNodeOrdering(Graph graph, CompareFn cmpFn);
Usage:
setNodeOrdering(graph, cmpFn);
void setArcOrdering(Graph graph, CompareFn cmpFn);
Usage:
setArcOrdering(graph, cmpFn);