e88c9fd73e3b

Add `rootp` and `leafp`
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 18 Dec 2017 17:49:14 -0500
parents 8b15dad7dad2
children f87bd8fe8739
branches/tags (none)
files docs/01-installation.markdown docs/03-reference.markdown docs/index.markdown package.lisp src/directed-graph.lisp

Changes

--- a/docs/01-installation.markdown	Mon May 15 20:14:36 2017 +0000
+++ b/docs/01-installation.markdown	Mon Dec 18 17:49:14 2017 -0500
@@ -1,9 +1,7 @@
 Installation
 ============
 
-cl-digraph is compatible with Quicklisp, but not *in* Quicklisp (yet?).  You can
-clone the repository into your [Quicklisp local-projects][local] directory for
-now.
+cl-digraph can be installed with [Quicklisp][]: `(ql:quickload :cl-digraph)`
 
 The `cl-digraph` system contains the core API and has no dependencies.
 
@@ -12,6 +10,6 @@
 
 The `cl-digraph.test` system contains the test suite, which uses [1am][].
 
-[local]: https://www.quicklisp.org/beta/faq.html#local-project
+[quicklisp]: https://quicklisp.org/
 [1am]: https://github.com/lmj/1am
 [cl-dot]: https://github.com/michaelw/cl-dot
--- a/docs/03-reference.markdown	Mon May 15 20:14:36 2017 +0000
+++ b/docs/03-reference.markdown	Mon Dec 18 17:49:14 2017 -0500
@@ -108,6 +108,12 @@
 
   
 
+### `LEAFP` (function)
+
+    (LEAFP DIGRAPH VERTEX)
+
+Return whether `vertex` is a leaf vertex in `digraph`.
+
 ### `LEAFS` (function)
 
     (LEAFS DIGRAPH)
@@ -296,6 +302,12 @@
 
   
 
+### `ROOTP` (function)
+
+    (ROOTP DIGRAPH VERTEX)
+
+Return whether `vertex` is a root vertex in `digraph`.
+
 ### `ROOTS` (function)
 
     (ROOTS DIGRAPH)
--- a/docs/index.markdown	Mon May 15 20:14:36 2017 +0000
+++ b/docs/index.markdown	Mon Dec 18 17:49:14 2017 -0500
@@ -1,8 +1,6 @@
 cl-digraph is an implementation of a mutable [directed graph][] data structure
 for Common Lisp.
 
-[directed graph]: https://en.wikipedia.org/wiki/Directed_graph
-
 * **License:** MIT
 * **Documentation:** <https://sjl.bitbucket.io/cl-digraph/>
 * **Mercurial:** <http://bitbucket.org/sjl/cl-digraph/>
@@ -15,3 +13,5 @@
 
 The test suite currently passes in SBCL, CCL, ECL, and ABCL on OS X and Debian.
 Further testing is welcome.
+
+[directed graph]: https://en.wikipedia.org/wiki/Directed_graph
--- a/package.lisp	Mon May 15 20:14:36 2017 +0000
+++ b/package.lisp	Mon Dec 18 17:49:14 2017 -0500
@@ -12,6 +12,9 @@
     :roots
     :leafs
 
+    :rootp
+    :leafp
+
     :predecessors
     :successors
     :neighbors
--- a/src/directed-graph.lisp	Mon May 15 20:14:36 2017 +0000
+++ b/src/directed-graph.lisp	Mon Dec 18 17:49:14 2017 -0500
@@ -214,6 +214,15 @@
     result))
 
 
+(defun rootp (digraph vertex)
+  "Return whether `vertex` is a root vertex in `digraph`."
+  (null (pred digraph vertex)))
+
+(defun leafp (digraph vertex)
+  "Return whether `vertex` is a leaf vertex in `digraph`."
+  (null (succ digraph vertex)))
+
+
 ;;;; Iteration ----------------------------------------------------------------
 (defun mapc-vertices (function digraph)
   "Call `function` on each vertex in `digraph`.
@@ -369,7 +378,7 @@
   A root is a vertex with no incoming edges (i.e. in-degree 0).
 
   "
-  (remove-if-not (lambda (v) (null (pred digraph v)))
+  (remove-if-not (curry #'rootp digraph)
                  (vertices digraph)))
 
 (defun leafs (digraph)
@@ -380,7 +389,7 @@
   A root is a vertex with no outgoing edges (i.e. out-degree 0).
 
   "
-  (remove-if-not (lambda (v) (null (succ digraph v)))
+  (remove-if-not (curry #'leafp digraph)
                  (vertices digraph)))