# HG changeset patch # User Steve Losh # Date 1513637354 18000 # Node ID e88c9fd73e3ba3bcf94913a9a6cbc92b184430a6 # Parent 8b15dad7dad2edc01b0b4cf48b83ba8c0b8f40a1 Add `rootp` and `leafp` diff -r 8b15dad7dad2 -r e88c9fd73e3b docs/01-installation.markdown --- 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 diff -r 8b15dad7dad2 -r e88c9fd73e3b docs/03-reference.markdown --- 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) diff -r 8b15dad7dad2 -r e88c9fd73e3b docs/index.markdown --- 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:** * **Mercurial:** @@ -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 diff -r 8b15dad7dad2 -r e88c9fd73e3b package.lisp --- 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 diff -r 8b15dad7dad2 -r e88c9fd73e3b src/directed-graph.lisp --- 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)))