From: Gary King Date: Mon, 3 Jul 2006 02:43:01 +0000 (-0400) Subject: Switched to keyword arguments in make-filterd-graph and subgraph-containing for a... X-Git-Url: http://repo.macrolet.net/gitweb/?p=cl-graph.git;a=commitdiff_plain;h=2d52d1e533a3c73bffd2dd81620cc5bd540c314a Switched to keyword arguments in make-filterd-graph and subgraph-containing for a bit more flexibility darcs-hash:20060703024301-3cc5d-a4bd9f41d57e8a7dfe5541abb688d9d32002de2f.gz --- diff --git a/dev/api.lisp b/dev/api.lisp index aee6b66..fe5020c 100644 --- a/dev/api.lisp +++ b/dev/api.lisp @@ -197,7 +197,9 @@ rooted at root.")) ;;; --------------------------------------------------------------------------- -(defgeneric make-filtered-graph (old-graph test-fn &optional graph-completion-method depth) +(defgeneric make-filtered-graph (old-graph test-fn &key + graph-completion-method depth + new-graph) (:documentation "Takes a GRAPH and a TEST-FN (a single argument function returning NIL or non-NIL), and filters the graph nodes according to the test-fn (those that return non-NIL are accepted), returning @@ -658,7 +660,7 @@ and any other initialization arguments that make sense for the vertex class.")) (defgeneric complete-links (new-graph old-graph) (:documentation "Add edges between vertexes in the new-graph for which the matching vertexes in the old-graph have edges. The vertex matching is done using `find-vertex`.")) -(defgeneric subgraph-containing (graph vertex &optional depth) +(defgeneric subgraph-containing (graph vertex &key) (:documentation "Returns a new graph that is a subset of `graph` that contains `vertex` and all of the other vertexes that can be reached from vertex by paths of less than or equal of length `depth`. If depth is not specified, then the entire sub-graph reachable from vertex will be returned. [?? Edge weights are always assumed to be one.]")) ;;; --------------------------------------------------------------------------- diff --git a/dev/graph.lisp b/dev/graph.lisp index caa6cb6..a204446 100644 --- a/dev/graph.lisp +++ b/dev/graph.lisp @@ -1006,43 +1006,43 @@ nil gathers the entire closure(s)." (defmethod make-filtered-graph ((old-graph basic-graph) test-fn - &optional + &key (graph-completion-method nil) - (depth nil)) - (let ((new-graph - (copy-template old-graph))) - (ecase graph-completion-method - ((nil - :complete-links) - (iterate-vertexes old-graph - (lambda (vertex) - (when (funcall test-fn vertex) - (add-vertex new-graph (value vertex)))))) - ((:complete-closure-nodes-only - :complete-closure-with-links) - (let* ((old-graph-vertexes (collect-items old-graph :filter test-fn)) - (closure-vertexes - (get-transitive-closure old-graph-vertexes depth))) - (dolist (vertex closure-vertexes) - (add-vertex new-graph (copy-template vertex)))))) - - (ecase graph-completion-method + (depth nil) + (new-graph + (copy-template old-graph))) + (ecase graph-completion-method + ((nil + :complete-links) + (iterate-vertexes old-graph + (lambda (vertex) + (when (funcall test-fn vertex) + (add-vertex new-graph (value vertex)))))) + ((:complete-closure-nodes-only + :complete-closure-with-links) + (let* ((old-graph-vertexes (collect-items old-graph :filter test-fn)) + (closure-vertexes + (get-transitive-closure old-graph-vertexes depth))) + (dolist (vertex closure-vertexes) + (add-vertex new-graph (copy-template vertex)))))) + (ecase graph-completion-method ((nil :complete-closure-nodes-only) nil) ((:complete-links :complete-closure-with-links) (complete-links new-graph old-graph))) - - new-graph)) + new-graph) ;;; --------------------------------------------------------------------------- (defmethod subgraph-containing ((graph basic-graph) (vertex basic-vertex) - &optional (depth nil)) - (make-filtered-graph graph - #'(lambda (v) - (equal v vertex)) - :complete-closure-with-links - depth)) + &rest args &key (depth nil) (new-graph nil)) + (declare (ignore depth new-graph)) + (apply #'make-filtered-graph + graph + #'(lambda (v) + (equal v vertex)) + :graph-completion-method :complete-closure-with-links + args)) ;;; ---------------------------------------------------------------------------