Hierarchical data storage software

I'm looking for [free] server software for efficiently storing hierarchical data. My key concern is that an object or group of objects almost always has 2 "parents", and one or both parents can have different relationships with other parents, and these children should remain distinct from the common parents of other children.

Example:

A and B
    C
    D
    E and F
        G
        H
    E and I
        J
        K
L and M
    ...

      

I guess it will most likely be what I would rather use this with PHP, but I am open to learning a new language since this is a personal project without any restrictions. (I am using a Linux server, I don't want to change that)

Edit: To clarify my example - C, D and E are all direct descendants of A and B, F and I are descendants of something else, maybe the same thing, maybe not, G and K are direct descendants of both E, so and F, etc.

+2


source to share


2 answers


I'm not sure if this is exactly what you are looking for, but you can use Graphviz dot for model / graph relationships.Here's the updated content of the .dot file, similar to your clarification:

digraph G {
    compound = true // allow edges between clusters
    subgraph cluster_ab {
        rank = same;
        A -> B -> A
    }
    A -> C [ltail=cluster_ab]
    A -> D [ltail=cluster_ab]
    A -> E [ltail=cluster_ab]
    subgraph cluster_ef {
        rank = same;
        E -> F -> E
    }
    E -> G [ltail=cluster_ef]
    E -> H [ltail=cluster_ef]

    subgraph cluster_ei {
        E -> I -> E
    }
    I -> J [ltail=cluster_ei]
    I -> K [ltail=cluster_ei]
}

      

sample dot output http://img21.imageshack.us/img21/6177/64094067.png

This is a little different because you cannot create overlapping clusters (E-> I and E-> F). But I think this is more like the way you clarified, although not surprisingly E and I are brothers and sisters - I also needed to connect with me on J, K, otherwise there was a warning and it looked a little uglier ...

There are many libraries that interoperate with Graphviz / dot that will allow you to generate these types of graphs dynamically rather than manually I did. Then if you already have a library for storing / retrieving directed graphs, you can pretty much store hierarchical data. As for how efficient it is, as you mentioned in your question ... depends on how much data you store, of course.




As @Kim points out in the comments, you can end up with a rather simplified graph by treating siblings as pairs rather than separate nodes:
digraph G {
    "A,B" -> C
    "A,B" -> D
    "A,B" -> E
    "E,F" -> G
    "E,F" -> H

    "E,I" -> J
    "E,I" -> K
}

      

This is an obvious and graceful solution that I completely missed, although it remains a little ambiguous about the sister relationship when the overlap occurs (E again).

a simpler graph http://img35.imageshack.us/img35/8969/so2b.png

+5


source


It seems to me that it should be easier for you to write your own php classes, which will be much more suitable for your needs. Maybe something like this (pseudocode)

Class Item  
  [List of Item] Parents 
  [List of Item] Children

      



The challenge is to write methods to manage / create the complete structure. Keeping also the nbr level should help a lot in your case. You already have related questions on stackoverflow about storing hierarchical structures in a database.

+2


source







All Articles