pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jackson, DeJuan <djackson@cpsgroup.com>
To: Michael J Schout <mschout@mail.gkg-com.com>
To: PGSQL SQL <pgsql-sql@postgresql.org>
Subject: RE: [SQL] A path through a tree
Date: Wed, 20 Jan 1999 10:20:42 -0600
Message-ID: <F10BB1FAF801D111829B0060971D839F5F80C4@cpsmail> (raw)

Oh well only one request for the URLS.  But, hey that's enough of an
excuse for me, so here you go: 
	
http://www.dbmsmag.com/9603d06.html

http://www.dbmsmag.com/9604d06.html

http://www.dbmsmag.com/9605d06.html



> Hi.
> 
> Saw your message in the pgsql list.  I would be interested in 
> teh URL you
> mentioned where you found this information if you wouldnt 
> mind.  I have
> dones eomething similar toi this, but my solution is not as 
> robust as this
> one.  I basically just stored the node titles in one table, and made
> another table that tells which nodes are parents/children of 
> other nodes.
> Works pretty well for what I need since I only need to show 
> one "level" of
> the tree most of 'the time.  There are some times I need to 
> walk up the
> tree to get the path to the root, but my trees are very 
> shallow, so this
> only takes 3-4 selects :).  But I really like this solution 
> and would liek
> to see the url where you round it.
> 
> Thanks!
> 
> Mike
> > 
> > Well, last night I thought it over and a Good(tm) way to display
> > threading,  hit me.  If you don't ever delete a node, but 
> just it's data
> > you can use the l and r information recursively to display.
> > 
> > function display(nodeList[][], currentNode, depth) {
> >    printf("%s|_%s\n", spaces(depth*2), 
> nodeList[currentNode]['title']);
> >    numChildren = (nodeList[currentNode]['r'] -
> > nodeList[currentNode]['l'] - 1)/2;
> >    for(numNodes=0;numNodes < numChildren; 
> >        numNodes += display(nodeList, 
> currentNode+numNodes+1, depth+1)) ;
> >    numNodes++;
> >    return numNodes;
> > }
> > 
> > I hope my psudo-code is decipherable.
> > Looking at the tree from the previous message:
> >  l| r|data
> > --+--+----
> >  1|12|head
> >  2| 7|c1  
> >  3| 4|c11 
> >  5| 6|c12 
> >  8| 9|c2  
> > 10|11|c3  
> > (6 rows)
> > 
> > And using the information in the above function we get:
> > |_head
> >   |_c1
> >     |_c11
> >     |_c12
> >   |_c2
> >   |_c3
> > 
> > Collapsing and expanding branches could simply be an array 
> of booleans
> > that's checked at currentNode where true display current node with a
> > plus (link for html to expand) then return numChildren+1 
> otherwise do
> > the loop.
> > 
> > Just thought everybody might like to see this.
> > 	-DEJ
> > BTW if you want more examples of this data-layout of trees 
> I can send in
> > the URL's where I found it.
> > 
> 



view thread (6+ messages)

Message-ID: <F10BB1FAF801D111829B0060971D839F5F80C4@cpsmail>
Permalink:  ../F10BB1FAF801D111829B0060971D839F5F80C4@cpsmail/
Also on:    postgresql.org/message-id/F10BB1FAF801D111829B0060971D839F5F80C4@cpsmail

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: djackson@cpsgroup.com, mschout@mail.gkg-com.com
  Subject: Re: [SQL] A path through a tree
  In-Reply-To: <F10BB1FAF801D111829B0060971D839F5F80C4@cpsmail>
  References: <F10BB1FAF801D111829B0060971D839F5F80C4@cpsmail>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox