about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-03-18 18:02:07 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-03-18 18:02:07 -0700
commita05f713dc11a543ea97c1160990552260618f629 (patch)
tree75e0a6642c6014f19e6de2111ae6796160f2cab5
parent03a38835551088960427a1b7221e686ba8cb0822 (diff)
downloadteliva-a05f713dc11a543ea97c1160990552260618f629.tar.gz
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.
-rw-r--r--graphviz.tlv7
1 files changed, 3 insertions, 4 deletions
diff --git a/graphviz.tlv b/graphviz.tlv
index 5db0d23..941610e 100644
--- a/graphviz.tlv
+++ b/graphviz.tlv
@@ -738,10 +738,9 @@
     >        -- edge_stmt
     >        local tok3 = tokens:read()
     >        if graph[tok1] == nil then
-    >          graph[tok1] = {tok3}
-    >        else
-    >          append(graph[tok1], {tok3})
+    >          graph[tok1] = {}
     >        end
+    >        graph[tok1][tok3] = true
     >      elseif tok2 == '--' then
     >        error('unexpected token "--" in digraph; edges should be directed using "->"')
     >      elseif tok2 == '=' then
@@ -808,7 +807,7 @@
     >function sources(Graph)
     >  local is_target = {}
     >  for source, targets in pairs(Graph) do
-    >    for _, target in ipairs(targets) do
+    >    for target, _ in pairs(targets) do
     >      is_target[target] = true
     >    end
     >  end