Class ::tycho::Forest


Inherits: ::tycho::DirectedAcyclicGraph - Source File - Contents: public methods
A forest is a data structure that includes any number of trees. A tree is a directed acyclic graph with nodes that are either a root or have exactly one parent, and that have any number of children. This class provides methods to build, browse, and edit such a data structure. Data stored on the nodes of the trees are as in the base class Graph. A method is provided to encode the data structure as a list, which can, for example, be written to a file. A method is also provided to convert this list back into a forest.

Here is an example of how to use the Forest:

   catch {delete object foo}
   ::tycho::Forest foo
   foo add a {}
   foo add c {} a
   foo add d {} a
   ::tycho::post [foo describe]
The description that is posted in the last line will be: {{a aa {}} {c cc a} {d dd a}}, which is a list of nodes in the forest. Each node is a list of three items, the name, contents, and parent of the node. Notice that in this example there is only one tree in the forest.

Public constructs

Public Methods

add nodename contents {parents {}}
Add a node to a tree in the forest. Only one parent can be specified.
addArc parent child
Trigger an error (disabling base class methods).
depthFirstSort roots
Return a list of node names in the subgraph with the given roots. This includes the roots themselves and all descendants. The returned list contains one element for each node in the subgraph, beginning with the first root, then, in depth-first order, all descendants. Parents are always listed before their children. If no arguments are given, then the entire graph is sorted.

Index of classes



Author: Edward A. Lee
Version: @(#)Forest.itcl 1.8 11/02/96
Copyright: (c) 1995-1996 The Regents of the University of California.