graphviz: tweak data structure slightly

A node's edges contain an associative array of target nodes rather than
a linear array.

This way we automatically dedup edges when we load multiple graphs.
This commit is contained in:
Kartik K. Agaram 2022-03-18 18:02:07 -07:00
parent 03a3883555
commit a05f713dc1
1 changed files with 3 additions and 4 deletions

View File

@ -738,10 +738,9 @@
> -- edge_stmt > -- edge_stmt
> local tok3 = tokens:read() > local tok3 = tokens:read()
> if graph[tok1] == nil then > if graph[tok1] == nil then
> graph[tok1] = {tok3} > graph[tok1] = {}
> else
> append(graph[tok1], {tok3})
> end > end
> graph[tok1][tok3] = true
> elseif tok2 == '--' then > elseif tok2 == '--' then
> error('unexpected token "--" in digraph; edges should be directed using "->"') > error('unexpected token "--" in digraph; edges should be directed using "->"')
> elseif tok2 == '=' then > elseif tok2 == '=' then
@ -808,7 +807,7 @@
>function sources(Graph) >function sources(Graph)
> local is_target = {} > local is_target = {}
> for source, targets in pairs(Graph) do > for source, targets in pairs(Graph) do
> for _, target in ipairs(targets) do > for target, _ in pairs(targets) do
> is_target[target] = true > is_target[target] = true
> end > end
> end > end