summaryrefslogtreecommitdiff
path: root/guix/graph.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-05-23 23:03:23 +0200
committerLudovic Courtès <ludo@gnu.org>2016-05-24 00:06:01 +0200
commite144e3427da93b962c7620ce2bd64add8c83cfdc (patch)
tree2f1cd6dd65e764e8dab09d5fa97f86a62664617d /guix/graph.scm
parent623e4df42abd024e0a62ef0b30f9b550f37cba57 (diff)
downloadgnu-guix-e144e3427da93b962c7620ce2bd64add8c83cfdc.tar
gnu-guix-e144e3427da93b962c7620ce2bd64add8c83cfdc.tar.gz
graph: Add 'node-reachable-count'.
* guix/graph.scm (node-reachable-count): New procedure. * tests/graph.scm ("node-reachable-count"): New test.
Diffstat (limited to 'guix/graph.scm')
-rw-r--r--guix/graph.scm8
1 files changed, 8 insertions, 0 deletions
diff --git a/guix/graph.scm b/guix/graph.scm
index af589c5c67..735d340c2c 100644
--- a/guix/graph.scm
+++ b/guix/graph.scm
@@ -39,6 +39,7 @@
node-back-edges
traverse/depth-first
node-transitive-edges
+ node-reachable-count
%graphviz-backend
graph-backend?
@@ -126,6 +127,13 @@ procedure that, given a node, returns its list of direct dependents; it is
typically returned by 'node-edges' or 'node-back-edges'."
(traverse/depth-first cons '() nodes node-edges))
+(define (node-reachable-count nodes node-edges)
+ "Return the number of nodes reachable from NODES along NODE-EDGES."
+ (traverse/depth-first (lambda (_ count)
+ (+ 1 count))
+ 0
+ nodes node-edges))
+
;;;
;;; Graphviz export.