Tcl Library Source Code

EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA

[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]


struct::tree_v1 - Create and manipulate tree objects

Table Of Contents


package require Tcl 8.5 9
package require struct::tree ?1.2.3?

treeName option ?arg arg ...?
treeName append node ?-key key? value
treeName children node
treeName cut node
treeName delete node ?node ...?
treeName depth node
treeName destroy
treeName exists node
treeName get node ?-key key?
treeName getall node
treeName keys node
treeName keyexists node ?-key key?
treeName index node
treeName insert parent index ?child ?child ...??
treeName isleaf node
treeName lappend node ?-key key? value
treeName move parent index node ?node ...?
treeName next node
treeName numchildren node
treeName parent node
treeName previous node
treeName set node ?-key key? ?value?
treeName size ?node?
treeName splice parent from ?to? ?child?
treeName swap node1 node2
treeName unset node ?-key key?
treeName walk node ?-order order? ?-type type? -command cmd


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

A tree is a collection of named elements, called nodes, one of which is distinguished as a root, along with a relation ("parenthood") that places a hierarchical structure on the nodes. (Data Structures and Algorithms; Aho, Hopcroft and Ullman; Addison-Wesley, 1987). In addition to maintaining the node relationships, this tree implementation allows any number of keyed values to be associated with each node.

The element names can be arbitrary strings.

A tree is thus similar to an array, but with three important differences:

  1. Trees are accessed through an object command, whereas arrays are accessed as variables. (This means trees cannot be local to a procedure.)

  2. Trees have a hierarchical structure, whereas an array is just an unordered collection.

  3. Each node of a tree has a separate collection of attributes and values. This is like an array where every value is a dictionary.

The following commands are possible for tree objects:

Bugs, Ideas, Feedback

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

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.




Data structures


Copyright © 2002 Andreas Kupries