CSRT-NTUA / AlgoPlus

AlgoPlus is a C++17 library for complex data structures and algorithms
https://csrt-ntua.github.io/AlgoPlus
Apache License 2.0
141 stars 20 forks source link

Visualize for skip list #64

Closed aveldan closed 1 day ago

aveldan commented 3 days ago

Hey @spirosmaggioros I was trying to create a visualize for skip list. I saw it was missing it. I had a little bit of success but I am not sure how do I make the edges for same key nodes in different level to be perfectly vertical.

Below is the result from my trying. Screenshot from 2024-07-05 16-43-59

You see the 0 from all different levels should be ideally vertical. This is the dot file for the above image

digraph list {
rankdir=LR;
node [shape=record;]
k0l2 [label="{<f0> 0 | <f1> } | <f2> "];
k12l2 [label="{<f0> 12 | <f1> } | <f2> "];
k0l2:f1 -> k12l2:f0;
k0l1 [label="{<f0> 0 | <f1> } | <f2> "];
k0l2:f2 -> k0l1:f0;
k6l1 [label="{<f0> 6 | <f1> } | <f2> "];
k0l1:f1 -> k6l1:f0;
k12l1 [label="{<f0> 12 | <f1> } | <f2> "];
k6l1:f1 -> k12l1:f0;
k12l2:f2 -> k12l1:f0;
k0l0 [label="{<f0> 0 | <f1> } | <f2> "];
k0l1:f2 -> k0l0:f0 [rankdir=TB];
k3l0 [label="{<f0> 3 | <f1> } | <f2> "];
k0l0:f1 -> k3l0:f0;
k6l0 [label="{<f0> 6 | <f1> } | <f2> "];
k3l0:f1 -> k6l0:f0;
k6l1:f2 -> k6l0:f0;
k7l0 [label="{<f0> 7 | <f1> } | <f2> "];
k6l0:f1 -> k7l0:f0;
k9l0 [label="{<f0> 9 | <f1> } | <f2> "];
k7l0:f1 -> k9l0:f0;
k12l0 [label="{<f0> 12 | <f1> } | <f2> "];
k9l0:f1 -> k12l0:f0;
k12l1:f2 -> k12l0:f0;
}

Here in the dot file I am naming the nodes as k<key>l<level> so k6l0 [label="{<f0> 6 | <f1> } | <f2> "]; means node with key 6 in 0th level.

I have tried adding something like [rankdir=TB] in front of relevant edges. Also tried something like

subgraph cluster_0 {
        rankdir=TB;
        00:f2 -> 00:f0;
    }

But they don't work. You have any idea how to make it happen help me. I am not very much familiar with the dot file structure.

github-actions[bot] commented 3 days ago

Thank you for your interest in AlgoPlus, a maintainer will see your issue soon!

spirosmaggioros commented 3 days ago

You can look here: https://skiplist.readthedocs.io/en/latest/visualisations.html . I had in mind to make one, but i wanted to implement more stuff to just check the boxes, and when everything is ready look into the visualizations and examples. If you can make it work will be great.

spirosmaggioros commented 1 day ago

This is closed as @aveldan made it.