Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maintain versions of a tree

I have a tree datastructure having upto 1000 nodes at a particular level ( max depth of 8-9 levels).

I need to maintain versions of this entire tree. A version is created after some processing happens. Between these versions, the data in the nodes may change ( not more than a 100 or so).

As of now, I was cloning the entire tree for each new version, but the space consumption is huge after a few versions. I cannot entirely delete the previous version records since I need to keep a track of the changes.

Whats the optimal way to store these versions in the database? (If not the db, any alternative way).

like image 258
Yashveer Rana Avatar asked Nov 19 '25 20:11

Yashveer Rana


1 Answers

This is not a very straightforward problem, but it is a solved problem. In general, data structures that remember their history are called persistent data structures.

The linked Wikipedia page has an example of a persistent tree that you should look at.

The path copying approach is fairly simple to implement but doesn't have performance as good as is possible.

like image 129
Timothy Shields Avatar answered Nov 21 '25 10:11

Timothy Shields



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!