]> gitweb.factorcode.org Git - factor.git/blob - basis/graphs/graphs-docs.factor
45f7f81ae77192a86a5a67d83a3a34183b4202d1
[factor.git] / basis / graphs / graphs-docs.factor
1 USING: assocs hashtables help.markup help.syntax kernel sequences ;
2 IN: graphs
3
4 ARTICLE: "graphs" "Directed graph utilities"
5 "Words for treating associative mappings as directed graphs can be found in the " { $vocab-link "graphs" } " vocabulary. A directed graph is represented as an assoc mapping each vertex to a set of edges entering that vertex, where the set is itself an assoc, with equal keys and values."
6 $nl
7 "To create a new graph, just create an assoc, for example by calling " { $link <hashtable> } ". To add vertices and edges to a graph:"
8 { $subsections add-vertex }
9 "To remove vertices from the graph:"
10 { $subsections remove-vertex }
11 "Since graphs are represented as assocs, they can be cleared out by calling " { $link clear-assoc } "."
12 $nl
13 "You can perform queries on the graph:"
14 { $subsections closure }
15 "Directed graphs are used to maintain cross-referencing information for " { $link "definitions" } "." ;
16
17 ABOUT: "graphs"
18
19 HELP: add-vertex
20 { $values { "vertex" object } { "edges" sequence } { "graph" "an assoc mapping vertices to sequences of edges" } }
21 { $description "Adds a vertex to a directed graph, with " { $snippet "edges" } "  as the outward edges from the vertex." }
22 { $side-effects "graph" } ;
23
24 HELP: remove-vertex
25 { $values { "vertex" object } { "edges" sequence } { "graph" "an assoc mapping vertices to sequences of edges" } }
26 { $description "Removes a vertex from a graph, using the given edges sequence." } 
27 { $notes "The " { $snippet "edges" } " sequence must equal the value passed to " { $link add-vertex } ", otherwise some vertices of the graph may continue to refer to the removed vertex." }
28 { $side-effects "graph" } ;
29
30 HELP: closure
31 { $values { "vertex" object } { "quot" { $quotation ( vertex -- assoc ) } } { "assoc" "a new assoc" } }
32 { $description "Outputs a set of all vertices reachable from " { $snippet "vertex" } " via edges given by the quotation. The set always includes " { $snippet "vertex" } "." } ;