(use eggdoc) (define doc `((eggdoc:begin (name "graph-dfs") (description "Depth-first search in a graph.") (author (url "http://chicken.wiki.br/ivan raikov" "Ivan Raikov")) (history (version "1.8" "Ported to Chicken 4") (version "1.7" "Now using matchable extension") (version "1.6" "Unit tests updated to use testbase") (version "1.5" "Build script updated for better cross-platform compatibility") (version "1.4" "eggdoc documentation fix") (version "1.3" "License upgrade to GPL v3") (version "1.2" "Added support for chicken-setup -test") (version "1.1" "Fixed a syntactic error in graph-dfs-fold") (version "1.0" "Initial release")) (requires (url "iset.html" "iset") (url "matchable.html" "matchable")) (usage "(require-extension graph-dfs)") (download "graph-dfs.egg") (documentation (p "The graph-dfs library is an implementation of depth-first search " "on a graph object that follows the API of e.g. the " (url "digraph.html" "digraph egg") ".") (subsection "Depth-first-search procedures" (procedure "graph-dfs-foreach:: G FNODE FEDGE ROOTS -> UNDEFINED" (p "depth-first search iterator; given a list of initial nodes, " (tt "ROOTS") ", " "the successors of each initial node are visited in depth-first search order, " "and procedures " (tt "FNODE") " and " (tt "FEDGE") " are applied to " "each node or edge, respectively, as the graph is traversed. " (tt "FNODE") " is of the form " (tt "LAMBDA N -> _") " where " (tt "N") " is node number; and " (tt "FEDGE") " is of the form " (tt "LAMBDA EDGE") " where " (tt "EDGE") " is a list of the form " (tt "(I J INFO)") "; " (tt "I") " and " (tt "J") " are the nodes defining " "the edge, and " (tt "INFO") " is edge metadata.")) (procedure "graph-dfs-fold:: G FNODE FEDGE ROOTS NODE-INIT EDGE-INIT -> NODE-STATE EDGE-STATE" (p "depth-first search iterator with state; given a list of initial nodes, " (tt "ROOTS") ", and initial node state and edge state, " (tt "NODE-INIT") " and " (tt "EDGE-INIT") " the successors of each initial node are visited in " "depth-first search order, and procedures " (tt "FNODE") " and " (tt "FEDGE") " are applied to each node and the node state, or edge and the edge state, " "respectively, as the graph is traversed. " (tt "FNODE") " is of the form " (tt "LAMBDA N NODE-STATE -> NODE-STATE") " where " (tt "N") " is node number, and NODE-STATE can be of arbitrary type and " "must of the same type as " (tt "NODE-INIT") ". " (tt "FEDGE") " is of the form " (tt "LAMBDA EDGE EDGE-STATE") " where " (tt "EDGE") " is a list of the form " (tt "(I J INFO)") "; " (tt "I") " and " (tt "J") " are the nodes defining the edge, and " (tt "INFO") " is edge metadata; " (tt "EDGE-STATE") " must be of the same type " "as " (tt "EDGE-INIT"))) (procedure "graph-dfs-depth:: G ROOTS -> NODE-DEPTH TRAVERSAL-TIME" (p "depth-first search depth; given a list of initial nodes, " "this procedure computes shortest DFS depth for each nodes " "traversed, and the number of nodes visited while traversing " "the successors of each node. " (tt "NODE-DEPTH") " is an array that contains the corresponding DFS depth for each node; " (tt "TRAVERSAL-TIME") " is also an array, where each value is " "the number of nodes visited in the sub-graph of that node.")) (procedure "graph-preorder:: G ROOT -> ((NODE NUM) ... )" (p "compute the preorder traversal sequence number for each successor " "of the given initial node.")) (procedure "graph-postorder:: G ROOT -> ((NODE NUM) ... )" (p "compute the postorder traversal sequence number for each successor " "of the given initial node.")))) (examples (pre #<~A" ni nj))))) (else (error "invalid edge " e)))) used-by) (define roots (map car ((g 'roots)))) (graph-dfs-foreach g (lambda (n) (print (format "node ~A; " n))) (lambda (e) (print (format "edge ~A; " e))) roots) (graph-dfs-fold g (lambda (n ax) (cons (list 'node n) ax)) (lambda (e ax) (cons (list 'edge e) ax)) roots (list) (list)) EOF ) (license "Copyright Ivan Raikov and the Okinawa Institute of Science and Technology This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the GPL license can be found at ."))))) (if (eggdoc->html doc) (void))