Skip to content

Instantly share code, notes, and snippets.

@death
Created February 28, 2020 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save death/a8b3235834d9e5eecb723356f786cf52 to your computer and use it in GitHub Desktop.
Save death/a8b3235834d9e5eecb723356f786cf52 to your computer and use it in GitHub Desktop.
some graph patches
From a6186052bad077dc7d86d98ca8706c1453ff2969 Mon Sep 17 00:00:00 2001
From: death <death@adeht.org>
Date: Thu, 23 Jan 2020 23:58:14 +0200
Subject: [PATCH 1/2] dot: quote labels
---
dot.lisp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/dot.lisp b/dot.lisp
index 8c39aac..a03c998 100644
--- a/dot.lisp
+++ b/dot.lisp
@@ -169,7 +169,12 @@ a list of SUBGRAPH structures. RANKS is a list of RANK structures."))
subgraphs ranks)
;; by default edges are labeled with their values
(unless (assoc :label edge-attrs)
- (push (cons :label {edge-value graph}) edge-attrs))
+ (push (cons :label
+ (lambda (edge)
+ (let ((value (edge-value graph edge)))
+ (when value
+ (format nil "\"~A\"" value)))))
+ edge-attrs))
(format stream "~a to_dot {~%~{~a~}}~%"
(etypecase graph
(digraph "digraph")
--
2.25.1
From 7dd941b5594f62d2eede718f579124bd0cbc67f6 Mon Sep 17 00:00:00 2001
From: death <death@adeht.org>
Date: Wed, 29 Jan 2020 02:35:27 +0200
Subject: [PATCH 2/2] fix NEIGHBORS for undirected graphs
---
graph.lisp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/graph.lisp b/graph.lisp
index 60c9bd7..37ec396 100644
--- a/graph.lisp
+++ b/graph.lisp
@@ -753,7 +753,7 @@ EDGE2 will be combined."))
(:documentation "Return all nodes which share an edge with NODE in GRAPH."))
(defmethod neighbors ((graph graph) node)
- (apply {concatenate 'list} (node-edges graph node)))
+ (remove node (apply {concatenate 'list} (node-edges graph node))))
(defmethod neighbors ((digraph digraph) node)
(mapcan [#'cdr {member node}] (node-edges digraph node)))
--
2.25.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment