I’m looking for [free] server software to store hierarchal data efficiently. My key challenge is that an object or group of objects almost always has 2 “parents” and one or both parents can have different connections with other parents, and those descendants must remain distinct from the common parent’s other descendants.
Example:
A and B
C
D
E and F
G
H
E and I
J
K
L and M
...
I guess the gotcha will probably be that I’d strongly prefer to use this with PHP, but I’m open to learning a new language, as this is a personal project without any deadline. (I’m using a Linux server; I’m not willing to change that)
Edit:
To clarify my example – C, D and E are all direct descendants of both A and B, F and I are descendants of something else, possibly the same thing, possibly not, G and K are both direct descendants of both E and F, etc.
I’m not sure if this is exactly what you’re looking for, but you can use Graphviz dot to model/graph relationships. Here’s the updated content of the .dot file, more like your clarification:
sample dot output http://img21.imageshack.us/img21/6177/64094067.png
This one is a little different, because you can’t create overlapping clusters (E->I and E->F). But I think it’s more like the way you’ve clarified, even though it isn’t terribly apparent that E and I are siblings — I also had to make sure to link from I to J,K, otherwise there was a warning and it looked a bit uglier.
There are plenty of libraries that interface with Graphviz/dot that would let you generate these kinds of graphs dynamically, rather than by hand as I did. Then if you’ve already got a library to store/retrieve directed graphs, you’re pretty much there on storing hierarchical data. As to whether it’s efficient, as you mentioned in your question… depends on how much data you’re storing, of course.
As @Kim points out in the comments, you can get a quite simplified graph by treating siblings as pairs, rather than individual nodes:
It’s an obvious and elegant solution that I completely overlooked, although it remains a little ambiguous about sibling relationships when overlap occurs (E again).
simpler graph http://img35.imageshack.us/img35/8969/so2b.png