Re: Recommended modules for Parent-Child trees?
by tilly (Archbishop) on May 17, 2004 at 20:06 UTC
|
If you wish the nodes to be stored in a database, then I'd suggest reading (and understanding) Nested Set Trees. In the common case of insert occasionally, query often, they are far more efficient than the usual adjacency model that people think of.
Unfortunately I don't know of a module that automates generating them in Perl, and I'm not entirely sure what such a module should look like. (Which may be why I don't know of one...) So you'd have to do some reinvention, but at least you'd reinvent a good version. | [reply] |
|
Got it. Nested set trees are very, very cool. Wow! Thanks for that. The efficiency with which you could select siblings/parents/ancestors and subtrees is crazy, recursive queries always bugged me (I've implemented parent-child relationships before).
It's a bit hard to wrap my head around how to get it into code, but I can probably come up with something given the SQL in the article.
I need to figure out now if speed of execution outweighs speed of development, and figure out where I'm going to spend my time.
-Any sufficiently advanced technology is indistinguishable from doubletalk.
My Biz
| [reply] |
|
| [reply] |
|
Re: Recommended modules for Parent-Child trees?
by stvn (Monsignor) on May 17, 2004 at 20:19 UTC
|
Hero Zzyzzx,
As lachoy has already said, you can use Tree::Simple for this. Of course, I wrote it so I favor it heavily. As for a persistence layer, I have actually implemented several different ones for Tree::Simple over the years, only one of which has been packaged for on CPAN right now, it is called Tree::Parser. Tree::Parser is more appropriate for serializing Tree::Simple heirarchies to files, but could be made to use a DBI backend by writing a custom filter.
If you would like to tell me a little more about your application, I can possibly help you out by giving you some persistence code I have already written (if it is appropriate to your needs). At the very least, I might be able to point you in the right direction.
| [reply] |
|
| [reply] |
Re: Recommended modules for Parent-Child trees?
by perrin (Chancellor) on May 17, 2004 at 19:19 UTC
|
Tree::DAG_Node worked great for me, but it doesn't handle the DBI stuff automatically. I wrote a routine that walked the tree (easy to do with the provided API) and performed the SQL statements required to save each node in my database. | [reply] |
Re: Recommended modules for Parent-Child trees?
by lachoy (Parson) on May 17, 2004 at 18:52 UTC
|
While not DBI-backed Tree::Simple looks pretty useful. Even better: its docs have a brief comments on a number of other tree modules on CPAN.
| [reply] |
|
| [reply] |
|
| [reply] |
|
| [reply] |
|