You may want to check out this article: http://www.sitepoint.com/article.php/1105
It's a really good explanation of using a "modified preorder tree traversal" algorithm for storing and navigating trees (which may make your "pruning" problem much easier!) The article is specifically in the context of storing trees/hierarchical structures in a relational database, but the translation of these database structures into CFCs should be relatively straightforward.
A fair warning... it definitely took me a couple times reading through the article to really grasp what the author was talking about! Though there are definitely some tradeoffs to consider with the modified preorder tree traversal algorithm, it seems like a pretty solid solution for many different situations and is something to consider.
-Doug (CFCDev Newbie)
Nando wrote:
Do a walk of the tree, maintaining a list of nodeIDs (pageID or something)
that grows and shrinks as you walk.
Ummm ... sounds like i SHOULD know what this means but i don't. Not familar with the term 'walk' in programming speak. How does the list grow and shrink
When you find your node (the current
page), abort the walk. The start a new walk that will actually generate
your pruned tree, and use that list that you build (which will contain the
path to the target node) to determine what branches you need to
process and
which branches you can skip.
I probably don't understand this, again, because of the 'walk' term. Do you have a few minutes to explain a little more sometime?
[In the back of the class with arm raised ...]
Nando
You'll probably want to prepend a
NULL to the front, so that the 'parent' of the topmost node is represented in your list. Typically, you want to display the children of all the nodes in the list, but nothing else.
You can use a loop for both walks, and I'd definitely recommend it for the first walk, as a loop is a lot easier to break (CFBREAK) than a recursive function.
Cheers, barneyb
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nando Sent: Monday, December 01, 2003 3:25 PM To: [EMAIL PROTECTED] Subject: RE: [CFCDev] recursive functions
I'm caching the results of a few recursive function in an object that create a tree structure of the site nav and a linked breadcrumb trail for each page in the site. So the performance hit is only taken once in a great while. I DO have to agree with Sean that the code is much more elegant, and the depth of the tree is unlimited, something i didn't see how to do with loops, (but might now if i really thought about it.)
The next challenge is how to "prune" the siteMap tree to display only the navigation tree needed for a particular page - hopefully that's easy, but i haven't looked into it yet.
recursion-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Sean A Corfield Sent: Monday, December 01, 2003 11:40 PM To: [EMAIL PROTECTED] Subject: Re: [CFCDev] recursive functions
On Dec 1, 2003, at 1:47 PM, Patrick Branley wrote:
This is a very good point. Anything that can be done with
would assumecan also
be done using a loop.
Sometimes implementing an algorithm with a loop makes for horrendous code whereas recursive code can be elegant and simple - consider algorithms for processing tree-structured data!
Does anybody know if there is a performance increase ? I
expensivethereIt depends. Recursion relies on function calls which can be
isnt.
(creating a stack frame, pushing variables etc). If the algorithm ismanage 'context'
sufficiently complex, the extra work you have to do to
for a loop may exceed the function call overhead.
Sean A Corfield -- http://www.corfield.org/blog/
"If you're not annoying somebody, you're not really alive." -- Margaret Atwood
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
