caesar0301 / treelib

An efficient implementation of tree data structure in python 2/3.
http://treelib.readthedocs.io/en/latest/
Other
800 stars 185 forks source link

Create nodes with children instead of the parent #185

Closed ese-jdm418 closed 2 years ago

ese-jdm418 commented 2 years ago

Hi, I have just found this python library and it seems really useful with what I am trying to do regarding looking at stocks and flows with a hierarchal structure.

My only question is that when generating the nodes you have to define what the parent node is, is there a way to generate nodes by defining what the children are instead? As the format of the data I am trying to input provides the children for each node but not the parent.

This is more of a quality of life feature as I could code the data to find the parents to each node but it is just more laborious.

I would be very grateful if anyone could advise me if this is possible.

John.

liamlundy commented 2 years ago

It sounds like you are basically building the tree from the ground up correct? The biggest issue here is that when you do that you are basically creating multiple smaller trees and then combining them. There's nothing wrong with that, but you can't do that using just a single Tree structure. In your case, I would either rearrange the data to start from the top of the tree or just create these individual trees and merge them as you move up across levels.

liamlundy commented 2 years ago

Going to close this for now, but let me know if you have any more questions