pub fn beautify_graph(
parents: &[Vec<usize>],
priorities: &[usize],
) -> Vec<usize>Expand description
Produce an order of “nodes” in a graph for cleaner graph output. For example, turn:
0-1---3---5---7---9---11--12
/ \
2---4---6 8---10
# [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]into:
0-1-3-5-------7------9-11-12
/ \
2-4-6 8-10
# [12, 11, 9, 10, 8, 7, 6, 4, 2, 5, 3, 1, 0]This function takes a slice of integers as graph “nodes”. The callsite should maintain mapping between the integers and real graph “nodes” (vertexes, ids, etc.).
The algorithm works by DFSing from roots to heads following the
parent->child edges. It was originally implemented in smartlog.py.
By default, longer branches get output first (for a fork), or last (for a
merge). This makes a typical vertical graph rendering algorithm more
likely put longer branches in the first column, result in less indentation
overall. This can be overridden by priorities. priorities and their
ancestors are more likely outputted in the first column. For a typical
vertical graph rendering algorithm, priorities is usually set to the
head of the main branch.