Re: Hierachical structures - an overview

From: Lennart Jonsson <lennart_at_kommunicera.umea.se>
Date: 4 Jan 2004 20:06:44 -0800
Message-ID: <6dae7e65.0401042006.199af0ea_at_posting.google.com>


"Mike MacSween" <mike.macsween.nospam_at_btinternet.com> wrote in message news:<3ff84593$0$52882$5a6aecb4_at_news.aaisp.net.uk>...
> "Lennart Jonsson" <lennart_at_kommunicera.umea.se> wrote in message
>
> > > 1a. Adjacency list + as per:
> > > http://fungus.teststation.com/~jon/treehandling/TreeHandling.htm
> > > Not sure about this. It claims to give the path upwards. It looks like
> it
> > > merely gives the ancestors, which isn't the same thing.
>
> Thanks you for putting me onto that in the first place
>
> > In what way does this differ? Are you meaning that the set of
> > ancestors is unordered, compared to the path?
>
> I think so

Guess it all comes down to how path is defined. In the doc it is defined as a union -> a set -> unorderd

>
> > In that case the path is
> > easy to create from the ancestor set.
>
> No doubt. I'll have a go (unless you can do it off the top of your head).
>

Just count the number of ancestors for each ancestor in the path. I.e something like:

select

     p.ancestor_id,
    (select count(1) from path where id = p.ancestor_id) as depth from

     path p
where

     id = ?
order by depth

[...]

HTH
/Lennart Received on Mon Jan 05 2004 - 05:06:44 CET

Original text of this message