incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jo-Erlend Schinstad <>
Subject Modeling a tree in couchdb.
Date Fri, 23 Dec 2011 10:47:38 GMT
For quite some time, I've been thinking about creating a Gtk TreeModel 
that uses CouchDB as a backend. I've just started investigating it and 
I've found some issues I don't know how to solve. I think this would be 
useful for all kinds of trees, though, so it wouldn't be specific to 
GTK. I hope someone can help.

The general idea is simple. The tree consists of nodes that can have 
zero or one parent and zero or more children. So I thought each node 
would be its own document with an ID like [model number, root node 
number, child node number, child...], for instance,
{ "_id":[0, 0, 1,2] } would be the third child of the second child of 
the first root node in the first model. This way, it would be easy to 
get a single node or a range of nodes (including children) from a 
specific model.

I have two problems with this; inserting, removing and moving nodes. If 
I insert a node somewhere in the middle, all the documents after it 
would need to get their IDs changed. I guess I could do this by looping 
backwards from the end, incrementing the id in order to create a free 
slot for the new node, (opposite for removals) but wouldn't this be 
extremely slow for large collections? It should also be possible to 
reorder rows, or just move something one step up or down. This would 
ideally mean simply swapping the IDs of two documents, but I don't know 
how to do this. I could give the first document a temporary value, then 
change the value for the second to the old value of the first, and then 
give the first the old value for the second. But the temporary value 
might itself cause problems.

Any ideas or thoughts? I appreciate your insight.

Jo-Erlend Schinstad

View raw message