Saturday, March 19, 2011

Linked list representation using dot language

As directed by the first post on Dot language, it can used in several other applications for representing diagrams with minimal effort(unlike paint or sophisticated draw tools). One of such applications I came across last week was to represent a linked list. A linked list can be viewed as a rank sorted graph on the horizontal than the vertical(the graph earlier described in the first post). The only major part where this system fails is when you need to specify some handles on the nodes, then they may not be exactly on the vertical as desired. I am working on this and if I get a solution will post it for the benefit of many in search of this answer.


The following is the dot code I used for creating a linked list. It uses a concept of "port" in the label attribute described in the code using <.>. Earlier we connected nodes to other nodes for specifying the edge connectivity. Now instead we also specify the port of connection thereby making the linked list more sound in its diagrammatic view

digraph G {
 nodesep=.05;
 rankdir = LR;
 nodex [shape=plaintext, label="......"];
 node0 [shape=record,label="<le> pid : 1000 | page : 0x00FF9933 | <link>"];
 node1 [shape=record,label="<le> pid : 1000 | page : 0x00FF9936 | <link>"];
 node5 [shape=record,label="<le> pid : 1000 | page : 0x00FF9934 | <link>"];
 node2 [shape=record,label="pid : 1001 | page : 0x003C8320 | <link>"];
 node3 [shape=record,label="pid : 1001 | page : 0x003C8324 | <link>"];
 node4 [shape=record,label="pid : 1001 | page : 0x003C9000 | <link>"];
 nodey [shape=plaintext, label="......"];
 lstentry0 [label = "start_FIFO"];
 lstentry1 [label = "end_FIFO"];
 { rank=source; "nodex"; }
 nodex -> node0:<link>;
 node0:<link> -> node5:<link>;
 node5:<link> -> node1:<link>;
 node1:<link> -> node2:<link>;
 node2:<link> -> node3:<link>;
 node3:<link> -> node4:<link>;
 node4:<link> -> nodey;
 lstentry0 -> node0:<le>;
 lstentry1 -> node1:<le>;
}
The image can be found at this place.

No comments:

Post a Comment