The ::struct::graph command creates a new
graph object with an associated global Tcl command whose name is graphName. This command may be used to invoke
various operations on the graph. It has the following general
form:

A directed graph is a structure containing two collections of
elements, called nodes and arcs respectively,
together with a relation ("connectivity") that places a general
structure upon the nodes and arcs.

Each arc is connected to two nodes, one of which is called the
source and the other the target. This imposes a
direction upon the arc, which is said to go from the source to the
target. It is allowed that source and target of an arc are the same
node. Such an arc is called a loop. Whenever a node is
source or target of an arc both are said to be adjacent.
This extends into a relation between nodes, i.e. if two nodes are
connected through at least one arc they are said to be
adjacent too.

Each node can be the source and target for any number of arcs.
The former are called the outgoing arcs of the node, the
latter the incoming arcs of the node. The number of edges
in either set is called the in- resp. the
out-degree of the node.

In addition to maintaining the node and arc relationships, this
graph implementation allows any number of keyed values to be
associated with each node and arc.

Set or get one of the keyed values associated with an arc. If no
key is specified, the key data is assumed.
Each arc that is added to a graph has the empty string assigned to
the key data automatically. An arc may have
any number of keyed values associated with it. If value is not specified, this command returns the current
value assigned to the key; if value is
specified, this command assigns that value to the key.

Return a list of arcs in the graph. If no restriction is
specified a list containing all arcs is returned. Restrictions can
limit the list of returned arcs based on the nodes that are
connected by the arc, on the keyed values associated with the arc,
or both. The restrictions that involve connected nodes have a list
of nodes as argument, specified after the name of the restriction
itself.

-in

Return a list of all arcs whose target is one of the nodes in
the nodelist.

-out

Return a list of all arcs whose source is one of the nodes in
the nodelist.

-adj

Return a list of all arcs adjacent to at least one of the nodes
in the nodelist. This is the union of the nodes
returned by -in and -out.

-inner

Return a list of all arcs adjacent to two of the nodes in the nodelist. This is the set of arcs in the subgraph
spawned by the specified nodes.

-embedding

Return a list of all arcs adjacent to exactly one of the nodes
in the nodelist. This is the set of arcs
connecting the subgraph spawned by the specified nodes to the rest
of the graph.

-keykey

Limit the list of arcs that are returned to those arcs that have
an associated key key.

-valuevalue

This restriction can only be used in combination with -key. It limits the list of arcs that are returned to
those arcs whose associated key key has the
value value.

The restrictions imposed by either -in, -out, -adj, -inner, or -embedded are applied
first. Specifying more than one of them is illegal. At last the
restrictions set via -key (and -value) are applied. Specifying more than one -key (and -value) is
illegal.

Set or get one of the keyed values associated with a node. If no
key is specified, the key data is assumed.
Each node that is added to a graph has the empty string assigned to
the key data automatically. A node may have
any number of keyed values associated with it. If value is not specified, this command returns the current
value assigned to the key; if value is
specified, this command assigns that value to the key.

Return a list of nodes in the graph. Restrictions can limit the
list of returned nodes based on neighboring nodes, or based on the
keyed values associated with the node. The restrictions that
involve neighboring nodes have a list of nodes as argument,
specified after the name of the restriction itself.

The possible restrictions are the same as for method arcs. The set of nodes to return is computed as the
union of all source and target nodes for all the arcs satisfying
the restriction as defined for arcs.

Set or get one of the keyed values associated with a graph. If
no key is specified, the key data is assumed.
Each graph has the empty string assigned to the key data automatically. A graph may have any number of
keyed values associated with it. If value is not
specified, this command returns the current value assigned to the
key; if value is specified, this command assigns
that value to the key.

Perform a breadth-first or depth-first walk of the graph
starting at the node node going in either the
direction of outgoing or opposite to the incoming arcs.

The type of walk, breadth-first or depth-first, is determined by
the value of type; bfs
indicates breadth-first, dfs indicates
depth-first. Depth-first is the default.

The order of the walk, pre-order, post-order or both-order is
determined by the value of order; pre indicates pre-order, post
indicates post-order, both indicates
both-order. Pre-order is the default. Pre-order walking means that
a node is visited before any of its neighbors (as defined by the direction, see below). Post-order walking means
that a parent is visited after any of its neighbors. Both-order
walking means that a node is visited before and after any
of its neighbors. The combination of a bread-first walk with post-
or both-order is illegal.

The direction of the walk is determined by the value of dir; backward indicates the
direction opposite to the incoming arcs, forward indicates the direction of the outgoing
arcs.

As the walk progresses, the command cmd will
be evaluated at each node, with the mode of the call (enter or leave) and values graphName and the name of the current node
appended. For a pre-order walk, all nodes are entered, for a post-order all nodes are left. In a
both-order walk the first visit of a node enters it, the second visit leaves
it.

This document, and the package it describes, will undoubtedly
contain bugs and other problems. Please report such in the category
struct :: graph of the Tcllib Trackers. Please
also report any ideas for enhancements you may have for either
package and/or documentation.