From: Ray Blaak <blaak@infomatch.com>
Subject: Re: package dependence question
Date: 2000/05/29
Date: 2000-05-29T00:00:00+00:00 [thread overview]
Message-ID: <un1l9gg26.fsf@infomatch.com> (raw)
In-Reply-To: 393296FB.78AA031D@acm.org
Jeff Carter <jrcarter@acm.org> writes:
> Carl Banks wrote:
> > So let's say that a particular tree has a different type of node at
> > each level. For example, type A is the root of the tree. Its
> > branches are of type B. B's branches are of type C, and so on.
>
> Then this isn't really a tree; it's a hierarchy. Trees have the same
> type everywhere a value is stored. Hierarchies are shaped like trees,
> but are used differently.
I disagree. A tree is simply a directed graph without cycles. There is no
requirement that all nodes must be of the same type. In particular, a
hierarchy is a tree.
However, in an OO implementation of a tree, all nodes will usually be of a
common type so that one can specify parent/child relationships in one
place. There can certainly be more specialized types for different kinds of
nodes.
E.g.
type TreeNode is tagged record
end record;
-- common stuff for all nodes, especially knowledge of the parent, child
-- containers, etc.
function ParentOf(n : TreeNode) : TreeNode;
function ChildCount(n : TreeNode) : Natural;
function ChildAt(n : TreeNode; index : Natural) : TreeNode;
procedure InsertChild(child : in out TreeNode; intoParent : in out TreeNode);
-- root node specialization
type A is new TreeNode with ... end record;
type B is new TreeNode with ... end record;
-- leaf nodes?
type C is new TreeNode with ... end record;
In this case the nodes are simultaneously of the same type (i.e. TreeNode) and
yet are different types (A, B, C, ...).
--
Cheers, The Rhythm is around me,
The Rhythm has control.
Ray Blaak The Rhythm is inside me,
blaak@infomatch.com The Rhythm has my soul.
next prev parent reply other threads:[~2000-05-29 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-29 0:00 package dependence question Carl Banks
2000-05-29 0:00 ` Robert Dewar
2000-05-29 0:00 ` Antonio Dur�n Dom�nguez
2000-06-03 0:00 ` Robert I. Eachus
2000-05-29 0:00 ` Jeff Carter
2000-05-29 0:00 ` Ray Blaak [this message]
2000-05-30 0:00 ` Robert A Duff
2000-05-30 0:00 ` Brian Rogoff
2000-05-30 0:00 ` Ray Blaak
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox