I have recently been playing around with a database type program to allow me to search easily through my scientific data. I would like to impose a tree type structure on this data, separate from that imposed by the filing system. Of course, I googled various ways to store tree type data, and they all seemed enormously complicated, but then an alternative occurred to me; suppose we store the following tree:
Breakfast L_____Spam L_____Eggs L_____Fritters Dinner L_____Moules marinières L_____Pâté de foie gras L_____Beluga caviar L_____Drinks L_____Château Latour L_____Brown ale L_____Wafer thin mint
simply as the following set of value pairs (where the names would be replaced with node ids, I expect)
Breakfast 1 Spam 2 Eggs 2 Fritters 2 Dinner 1 Moules marinières 2 Pâté de foie gras 2 Beluga caviar 2 Drinks 2 Château Latour 3 Brown ale 3 Wafer thin mint 2
where the number is quite clearly the generation into the tree for that item. It is now straightforward to find an item's parent, its descendants of different levels, its siblings - querying the tree seems now easy. It is also very human readable.
I imagine the disadvantage is that it is slow to rearrange. But if we turn it into a doubly linked list, maybe these disadvantages are mitigated. Is this a terrible method? Have I just rediscovered something really obvious? Any thoughts would be appreciated.