Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dev/api.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,22 @@ as a source. [?? Could be a defun]."))
are out-going\). (cf. rootp) [?? could be a defun]"))


(defgeneric graph-leaves (graph)
(:documentation "Returns a list of the leaves of graph. A leaf is
defined as a vertex with no target edges \(i.e., all of the edges
are incoming\). (cf. targetp) [?? could be a defun]"))


(defgeneric rootp (vertex)
(:documentation "Returns true if `vertex` is a root vertex \(i.e.,
it has no incoming \(source\) edges\)."))


(defgeneric leafp (vertex)
(:documentation "Returns true if `vertex` is a leaf vertex \(i.e.,
it has no outgoing \(target\) edges\)."))


(defgeneric find-vertex-if (thing predicate &key key)
(:documentation "Returns the first vertex in `thing` for which the
`predicate` function returns non-nil. If the `key` is supplied, then
Expand Down
8 changes: 8 additions & 0 deletions dev/graph.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,19 @@ something is putting something on the vertexes plist's
(collect-elements (graph-vertexes graph) :filter #'rootp))


(defmethod graph-leaves ((graph basic-graph))
(collect-elements (graph-vertexes graph) :filter #'leafp))


(defmethod rootp ((vertex basic-vertex))
;;?? this is inefficient in the same way that (zerop (length <list>)) is...
(zerop (target-edge-count vertex)))


(defmethod leafp ((vertex basic-vertex))
(zerop (source-edge-count vertex)))


(defmethod find-vertex-if ((graph basic-graph) fn &key key)
(iterate-vertexes graph
(lambda (v)
Expand Down
2 changes: 2 additions & 0 deletions dev/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ DISCUSSION
#:target-edge-count ; vertex

#:rootp ; vertex
#:leafp ; vertex
#:graph-roots ; graph
#:graph-leaves ; graph

#:topological-sort ; graph
#:depth ; graph | vertex
Expand Down