[Neo] is neo4j the correct tool to store trees?
craig at amanzi.com
Tue Apr 6 16:06:59 CEST 2010
You are right, the graph is a natural way to describe a tree (or a tree is a
type of graph). I usually construct trees with a simple CHILD relationship,
so each directory will have outgoing CHILD relationships to all
sub-directories and files. You can traverse from the root to any file or
depth using a traverser, but actually a more common pattern is to only
iterate the relationships from the current node. That is the same as a 'dir'
or 'ls' command. This makes it very easy also to visualize the tree in the
GUI. When the user clicks the expand icon on a tree node, you iterate the
children and populate the tree dynamically.
Of course it is trivial to move branches around by simply re-linking (adding
and removing CHILD relationships).
Sorting children can be done in the client (during iteration of child
nodes), or alternatively persisted in the database with ordering
relationships between the child nodes. For example I sometimes use NEXT
relationships to define order. Persisting it in the database is only useful
if you have very large child sets, and don't want to load them all into
memory at once. If they are extremely large, you can also remove the CHILD
relationships (all but to the first CHILD), so that you don't have too many
relationships from the parent. This problem is unlikely in any filesystem
which has much more limited thresholds than neo4j, but it could happen in
some some tree-like data.
On Tue, Apr 6, 2010 at 3:26 PM, TuX RaceR <tuxracer69 at gmail.com> wrote:
> Hello Neo4j Users,
> his is a newbie question.
> I have a tree that could be thought of as a filesystem tree, i.e:
> with possibly long paths
> As far as I understand a Tree is a particular case of a graph.
> Each node has a NodeID (like a Inode in a unix filesystem) and a Name
> (as metadata, which can be non ASCII)
> Common operations will be:
> give me the node ID based on the node path
> I guess there one could implement a traverser class to navigate to the
> node at the end of the path based on names lookup, but it seems not very
> natural when looking at the neo4j api. It seems the API is more
> designed to get whole tress or first neighbours.
> Also the data will be mutable, i.e. a path
> could be renamed into:
> Thanks in advance
> Neo mailing list
> User at lists.neo4j.org
More information about the User