dbTalk Databases Forums  

how to suppress carefully a recursive tree

comp.databases.theory comp.databases.theory


Discuss how to suppress carefully a recursive tree in the comp.databases.theory forum.



Reply
 
Thread Tools Display Modes
  #121  
Old   
fj
 
Posts: n/a

Default Re: how to suppress carefully a recursive tree - 01-24-2008 , 09:37 PM






Quote:
Step 3 only involves a *single* mark and sweep. It begins by flagging
all the roots as visited and pushing them on a stack. The mark phase
involves popping a node from the stack and pushing adjacent nodes that
haven't yet been visited, until the stack is empty. Note that it is
best to mark nodes as visited as they are pushed onto the stack
(rather than when they're popped). So at all times the stack only
contains nodes that have been marked as visited. This makes it clear
that the algorithm will never process a node more than once.

Step 3 will typically be faster than step 1 even though it may start
with multiple roots. The time taken by a trace has more to do with
the total number of visited nodes than the initial number of roots,
and step 3 always visits a subset of the nodes that were visited in
step 1.
OK you are right. I did not realize that this algorithm was not fully
recursive because one visit only non marked objects.

I have programmed it and it seems to work correctly. But I think that
I will adopt the Python strategy :
- for deleting a tree or a branch, I just decrement the reference
count of its root first and I delete it really (and sub-objects
recursively) if the count is equal to zero. This can be done
everywhere in my application but lost objects (those with recursion)
may remain undeleted.
- from time to time, in a single thread part of the application, I can
decide to call a garbage collector which examines all the container
objects. This is possible because I always keep information (pointer)
about all the created objects. The step 1 is even simplified because I
don't need to go down the containers recursively : I know all the
containers and I just have to examine container sub-objects at the
first level. At the end of this step I know all the root containers
(those which have been protected somewhere in increasing their
reference count without storing them in a container). Then I start
steps 2 and 3.

I have programmed this strategy and it seem to work ... on two simple
examples with few nodes, from 6 (the example proposed) to 15000 (a
short test case). I have now to test it in real conditions (in general
about 1 million of containers for 5 to 10 millions of objects for a
big test case) and measure performances.

Thank you very much for your help !

F. Jacq



Reply With Quote
  #122  
Old   
-CELKO-
 
Posts: n/a

Default Re: how to suppress carefully a recursive tree - 01-26-2008 , 02:11 AM






Get a copy of TREES & HIERARCHIES IN SQL and look up the Nested Sets
model. You can Google it for the basic idea.

You would put the nodes into one table and the structure into a second
table with (lft, rgt) as its key, then reference the node for that
position.

Jan, sorry to be late, but I was out of town this week

Reply With Quote
  #123  
Old   
-CELKO-
 
Posts: n/a

Default Re: how to suppress carefully a recursive tree - 01-26-2008 , 02:11 AM



Get a copy of TREES & HIERARCHIES IN SQL and look up the Nested Sets
model. You can Google it for the basic idea.

You would put the nodes into one table and the structure into a second
table with (lft, rgt) as its key, then reference the node for that
position.

Jan, sorry to be late, but I was out of town this week

Reply With Quote
  #124  
Old   
-CELKO-
 
Posts: n/a

Default Re: how to suppress carefully a recursive tree - 01-26-2008 , 02:11 AM



Get a copy of TREES & HIERARCHIES IN SQL and look up the Nested Sets
model. You can Google it for the basic idea.

You would put the nodes into one table and the structure into a second
table with (lft, rgt) as its key, then reference the node for that
position.

Jan, sorry to be late, but I was out of town this week

Reply With Quote
  #125  
Old   
-CELKO-
 
Posts: n/a

Default Re: how to suppress carefully a recursive tree - 01-26-2008 , 02:11 AM



Get a copy of TREES & HIERARCHIES IN SQL and look up the Nested Sets
model. You can Google it for the basic idea.

You would put the nodes into one table and the structure into a second
table with (lft, rgt) as its key, then reference the node for that
position.

Jan, sorry to be late, but I was out of town this week

Reply With Quote
  #126  
Old   
-CELKO-
 
Posts: n/a

Default Re: how to suppress carefully a recursive tree - 01-26-2008 , 02:11 AM



Get a copy of TREES & HIERARCHIES IN SQL and look up the Nested Sets
model. You can Google it for the basic idea.

You would put the nodes into one table and the structure into a second
table with (lft, rgt) as its key, then reference the node for that
position.

Jan, sorry to be late, but I was out of town this week

Reply With Quote
  #127  
Old   
-CELKO-
 
Posts: n/a

Default Re: how to suppress carefully a recursive tree - 01-26-2008 , 02:11 AM



Get a copy of TREES & HIERARCHIES IN SQL and look up the Nested Sets
model. You can Google it for the basic idea.

You would put the nodes into one table and the structure into a second
table with (lft, rgt) as its key, then reference the node for that
position.

Jan, sorry to be late, but I was out of town this week

Reply With Quote
  #128  
Old   
-CELKO-
 
Posts: n/a

Default Re: how to suppress carefully a recursive tree - 01-26-2008 , 02:11 AM



Get a copy of TREES & HIERARCHIES IN SQL and look up the Nested Sets
model. You can Google it for the basic idea.

You would put the nodes into one table and the structure into a second
table with (lft, rgt) as its key, then reference the node for that
position.

Jan, sorry to be late, but I was out of town this week

Reply With Quote
  #129  
Old   
-CELKO-
 
Posts: n/a

Default Re: how to suppress carefully a recursive tree - 01-26-2008 , 02:11 AM



Get a copy of TREES & HIERARCHIES IN SQL and look up the Nested Sets
model. You can Google it for the basic idea.

You would put the nodes into one table and the structure into a second
table with (lft, rgt) as its key, then reference the node for that
position.

Jan, sorry to be late, but I was out of town this week

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.