cgraph: Forcing node order as in addNewNodeBefore()

My application needs to be able to delete nodes and add new nodes at a specific index within the node list.

16 Open Issues: Node and Edge Ordering. The intent in Cgraph’s design was to eventually support user-defined node and edge set ordering, overriding the default (which is object creation timestamp order).

If this is not possible, it seems that the easiest way to implement adddNewNodeBefore(Agraph_t *G, char *name, Agnode_t *beforeNd) would be to create a new graph

1. copy/clone/insert nodes and edges before node "beforeNd"
2. inserting the new node "u"
3. copy/clone/insert nodes and edges after node "beforeNd"

Any help will be greatly appreciated.

Thanks,

TR

Re: cgraph: Forcing node order as in addNewNodeBefore()

OK, I've added a function int agnodebefore(Agnode *u, Agnode_t *v) that

forces u before v in the object order of the main graph and all subgraphs.

This doesn't create nodes; you can do that using the existing primitives
for that.

This code is in https://github.com/ellson/graphviz

It should be added to man pages.

Stephen North

p.s. 1) I thought this could be done in a few lines of code,
which was true. 2) It still took two short evenings to get
it right. 3) I misunderstood the need for unique keys in
libcdt, at least as we use it. 4) Also had a trivial off-by-one
error. 5) These were easy to find because I suspected
the problems. 6) Despite clang and lldb, I had to resort to
printf debugging.  6) I did test it a little 7) but probably
something else is wrong and I'll be sorry.

 

Hi Stephen, I am

Hi Stephen,

I am forever grateful for the time that you put in. agnodebefore() is exactly what I needed. Node will be created as usual.  

Like your numbered list!!  It is always the little things that cost a whole of  time.  

Re. #7 - I will report back if some errors pop-up!

Best,

TR

Re: cgraph: Forcing node order as in addNewNodeBefore()

Thank you erg and Stephen,

1. I suppose, the application could maintain a list of ordered nodes and use name/indexed IDs for accessing the nodes. The travsersal would then be done over application-nodelist. It is a reasonable approach and farily straightforward to implement. Thanks for the suggestion.

2.  Stephen's suggested solution would be ideal. That would eliminate redundancies and simplify application logic.  I would much grateful, if such solution is implemented.  

Thanks,

TR 

By the way, the cdt library

By the way, the cdt library is ideal for 1. 

I know it might be

I know it might be inconvenient, but why not maintain your own list of nodes? Is there a reason you want to have control of the list of nodes within the graph? 

Re: cgraph: Forcing node order as in addNewNodeBefore()

Yes, the notion of "immutable" sequential object IDs is baked into graphviz.

These values are just used for maintaining the sequence of objects for traversals including I/O. I don't believe there's much other indexing - random access is based on IDs not on sequence numbers.

It might be possible to write a function of a few lines that increments existing sequence numbers and allows an existing one to be reassigned.  If I have time I will look at this in the next day or two.

Stephen North
 

Recent comments