]> gitweb.factorcode.org Git - factor.git/commitdiff
graphs: moving to basis.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 9 Mar 2013 16:31:06 +0000 (08:31 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 9 Mar 2013 16:31:06 +0000 (08:31 -0800)
13 files changed:
basis/graphs/authors.txt [new file with mode: 0644]
basis/graphs/graphs-docs.factor [new file with mode: 0644]
basis/graphs/graphs-tests.factor [new file with mode: 0644]
basis/graphs/graphs.factor [new file with mode: 0644]
basis/graphs/summary.txt [new file with mode: 0644]
basis/graphs/tags.txt [new file with mode: 0644]
core/generic/standard/standard-tests.factor
core/graphs/authors.txt [deleted file]
core/graphs/graphs-docs.factor [deleted file]
core/graphs/graphs-tests.factor [deleted file]
core/graphs/graphs.factor [deleted file]
core/graphs/summary.txt [deleted file]
core/graphs/tags.txt [deleted file]

diff --git a/basis/graphs/authors.txt b/basis/graphs/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/basis/graphs/graphs-docs.factor b/basis/graphs/graphs-docs.factor
new file mode 100644 (file)
index 0000000..a08a2a5
--- /dev/null
@@ -0,0 +1,32 @@
+USING: assocs hashtables help.markup help.syntax kernel sequences ;
+IN: graphs
+
+ARTICLE: "graphs" "Directed graph utilities"
+"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."
+$nl
+"To create a new graph, just create an assoc, for example by calling " { $link <hashtable> } ". To add vertices and edges to a graph:"
+{ $subsections add-vertex }
+"To remove vertices from the graph:"
+{ $subsections remove-vertex }
+"Since graphs are represented as assocs, they can be cleared out by calling " { $link clear-assoc } "."
+$nl
+"You can perform queries on the graph:"
+{ $subsections closure }
+"Directed graphs are used to maintain cross-referencing information for " { $link "definitions" } "." ;
+
+ABOUT: "graphs"
+
+HELP: add-vertex
+{ $values { "vertex" object } { "edges" sequence } { "graph" "an assoc mapping vertices to sequences of edges" } }
+{ $description "Adds a vertex to a directed graph, with " { $snippet "edges" } "  as the outward edges from the vertex." }
+{ $side-effects "graph" } ;
+
+HELP: remove-vertex
+{ $values { "vertex" object } { "edges" sequence } { "graph" "an assoc mapping vertices to sequences of edges" } }
+{ $description "Removes a vertex from a graph, using the given edges sequence." } 
+{ $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." }
+{ $side-effects "graph" } ;
+
+HELP: closure
+{ $values { "obj" object } { "quot" { $quotation "( obj -- assoc )" } } { "assoc" "a new assoc" } }
+{ $description "Outputs a set of all vertices reachable from " { $snippet "vertex" } " via edges given by the quotation. The set always includes " { $snippet "vertex" } "." } ;
diff --git a/basis/graphs/graphs-tests.factor b/basis/graphs/graphs-tests.factor
new file mode 100644 (file)
index 0000000..90b0e93
--- /dev/null
@@ -0,0 +1,50 @@
+USING: graphs tools.test namespaces kernel sorting assocs ;
+
+H{ } "g" set
+{ 1 2 3 } "v" set
+
+[ ] [ "v" dup get "g" get add-vertex ] unit-test
+
+[ { "v" } ] [ 1 "g" get at keys ] unit-test
+
+H{
+    { 1 H{ { 1 1 } { 2 2 } } }
+    { 2 H{ { 3 3 } { 4 4 } } }
+    { 4 H{ { 4 4 } { 5 5 } } }
+} "g" set
+
+[ { 2 3 4 5 } ] [
+    2 [ "g" get at ] closure keys natural-sort 
+] unit-test
+
+H{ } "g" set
+
+[ ] [
+    "mary"
+    H{ { "billy" "one" } { "joey" "two" } }
+    "g" get add-vertex*
+] unit-test
+
+[ H{ { "mary" "one" } } ] [
+    "billy" "g" get at
+] unit-test
+
+[ ] [
+    "liz"
+    H{ { "billy" "four" } { "fred" "three" } }
+    "g" get add-vertex*
+] unit-test
+
+[ H{ { "mary" "one" } { "liz" "four" } } ] [
+    "billy" "g" get at
+] unit-test
+
+[ ] [
+    "mary"
+    H{ { "billy" "one" } { "joey" "two" } }
+    "g" get remove-vertex*
+] unit-test
+
+[ H{ { "liz" "four" } } ] [
+    "billy" "g" get at
+] unit-test
diff --git a/basis/graphs/graphs.factor b/basis/graphs/graphs.factor
new file mode 100644 (file)
index 0000000..eed2a69
--- /dev/null
@@ -0,0 +1,45 @@
+! Copyright (C) 2006, 2007 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: assocs kernel sequences sets ;
+IN: graphs
+
+<PRIVATE
+
+: if-graph ( vertex edges graph quot -- )
+    dupd [ 3drop ] if ; inline
+
+: nest ( key graph -- hash )
+    [ drop H{ } clone ] cache ; inline
+
+PRIVATE>
+
+: add-vertex ( vertex edges graph -- )
+    [ [ nest dupd set-at ] curry with each ] if-graph ; inline
+
+: add-vertex* ( vertex edges graph -- )
+    [
+        swapd [ [ rot ] dip nest set-at ] 2curry assoc-each
+    ] if-graph ; inline
+
+: remove-vertex ( vertex edges graph -- )
+    [ [ at delete-at ] curry with each ] if-graph ; inline
+
+: remove-vertex* ( vertex edges graph -- )
+    [
+        swapd [ [ rot ] dip at delete-at drop ] 2curry assoc-each
+    ] if-graph ; inline
+
+<PRIVATE
+
+: (closure) ( obj assoc quot: ( elt -- assoc ) -- )
+    2over key? [
+        3drop
+    ] [
+        2over conjoin [ dip ] keep
+        [ [ drop ] 3dip (closure) ] 2curry assoc-each
+    ] if ; inline recursive
+
+PRIVATE>
+
+: closure ( obj quot -- assoc )
+    H{ } clone [ swap (closure) ] keep ; inline
diff --git a/basis/graphs/summary.txt b/basis/graphs/summary.txt
new file mode 100644 (file)
index 0000000..aced099
--- /dev/null
@@ -0,0 +1 @@
+Directed graphs
diff --git a/basis/graphs/tags.txt b/basis/graphs/tags.txt
new file mode 100644 (file)
index 0000000..42d711b
--- /dev/null
@@ -0,0 +1 @@
+collections
index 1a464e16d34d2f1cdf2080074ea79470e8fe82d1..9a4a4d6016a036195540aab9729210308fa17d38 100644 (file)
@@ -1,11 +1,9 @@
-USING: tools.test math math.functions math.constants
-generic.standard generic.single strings sequences arrays kernel
-accessors words byte-arrays bit-arrays parser namespaces make
-quotations stack-checker vectors growable hashtables sbufs
-prettyprint byte-vectors bit-vectors specialized-vectors
-definitions generic sets graphs assocs grouping see eval
-classes.union classes.tuple compiler.units io.streams.string
-compiler.crossref math.order ;
+USING: accessors arrays assocs bit-arrays bit-vectors
+byte-arrays classes.tuple classes.union compiler.crossref
+compiler.units definitions eval generic generic.single
+generic.standard io.streams.string kernel make math
+math.constants math.functions namespaces parser quotations
+sequences specialized-vectors strings tools.test words ;
 QUALIFIED-WITH: alien.c-types c
 FROM: namespaces => set ;
 SPECIALIZED-VECTOR: c:double
diff --git a/core/graphs/authors.txt b/core/graphs/authors.txt
deleted file mode 100644 (file)
index 1901f27..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Slava Pestov
diff --git a/core/graphs/graphs-docs.factor b/core/graphs/graphs-docs.factor
deleted file mode 100644 (file)
index a08a2a5..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-USING: assocs hashtables help.markup help.syntax kernel sequences ;
-IN: graphs
-
-ARTICLE: "graphs" "Directed graph utilities"
-"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."
-$nl
-"To create a new graph, just create an assoc, for example by calling " { $link <hashtable> } ". To add vertices and edges to a graph:"
-{ $subsections add-vertex }
-"To remove vertices from the graph:"
-{ $subsections remove-vertex }
-"Since graphs are represented as assocs, they can be cleared out by calling " { $link clear-assoc } "."
-$nl
-"You can perform queries on the graph:"
-{ $subsections closure }
-"Directed graphs are used to maintain cross-referencing information for " { $link "definitions" } "." ;
-
-ABOUT: "graphs"
-
-HELP: add-vertex
-{ $values { "vertex" object } { "edges" sequence } { "graph" "an assoc mapping vertices to sequences of edges" } }
-{ $description "Adds a vertex to a directed graph, with " { $snippet "edges" } "  as the outward edges from the vertex." }
-{ $side-effects "graph" } ;
-
-HELP: remove-vertex
-{ $values { "vertex" object } { "edges" sequence } { "graph" "an assoc mapping vertices to sequences of edges" } }
-{ $description "Removes a vertex from a graph, using the given edges sequence." } 
-{ $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." }
-{ $side-effects "graph" } ;
-
-HELP: closure
-{ $values { "obj" object } { "quot" { $quotation "( obj -- assoc )" } } { "assoc" "a new assoc" } }
-{ $description "Outputs a set of all vertices reachable from " { $snippet "vertex" } " via edges given by the quotation. The set always includes " { $snippet "vertex" } "." } ;
diff --git a/core/graphs/graphs-tests.factor b/core/graphs/graphs-tests.factor
deleted file mode 100644 (file)
index 90b0e93..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-USING: graphs tools.test namespaces kernel sorting assocs ;
-
-H{ } "g" set
-{ 1 2 3 } "v" set
-
-[ ] [ "v" dup get "g" get add-vertex ] unit-test
-
-[ { "v" } ] [ 1 "g" get at keys ] unit-test
-
-H{
-    { 1 H{ { 1 1 } { 2 2 } } }
-    { 2 H{ { 3 3 } { 4 4 } } }
-    { 4 H{ { 4 4 } { 5 5 } } }
-} "g" set
-
-[ { 2 3 4 5 } ] [
-    2 [ "g" get at ] closure keys natural-sort 
-] unit-test
-
-H{ } "g" set
-
-[ ] [
-    "mary"
-    H{ { "billy" "one" } { "joey" "two" } }
-    "g" get add-vertex*
-] unit-test
-
-[ H{ { "mary" "one" } } ] [
-    "billy" "g" get at
-] unit-test
-
-[ ] [
-    "liz"
-    H{ { "billy" "four" } { "fred" "three" } }
-    "g" get add-vertex*
-] unit-test
-
-[ H{ { "mary" "one" } { "liz" "four" } } ] [
-    "billy" "g" get at
-] unit-test
-
-[ ] [
-    "mary"
-    H{ { "billy" "one" } { "joey" "two" } }
-    "g" get remove-vertex*
-] unit-test
-
-[ H{ { "liz" "four" } } ] [
-    "billy" "g" get at
-] unit-test
diff --git a/core/graphs/graphs.factor b/core/graphs/graphs.factor
deleted file mode 100644 (file)
index eed2a69..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-! Copyright (C) 2006, 2007 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: assocs kernel sequences sets ;
-IN: graphs
-
-<PRIVATE
-
-: if-graph ( vertex edges graph quot -- )
-    dupd [ 3drop ] if ; inline
-
-: nest ( key graph -- hash )
-    [ drop H{ } clone ] cache ; inline
-
-PRIVATE>
-
-: add-vertex ( vertex edges graph -- )
-    [ [ nest dupd set-at ] curry with each ] if-graph ; inline
-
-: add-vertex* ( vertex edges graph -- )
-    [
-        swapd [ [ rot ] dip nest set-at ] 2curry assoc-each
-    ] if-graph ; inline
-
-: remove-vertex ( vertex edges graph -- )
-    [ [ at delete-at ] curry with each ] if-graph ; inline
-
-: remove-vertex* ( vertex edges graph -- )
-    [
-        swapd [ [ rot ] dip at delete-at drop ] 2curry assoc-each
-    ] if-graph ; inline
-
-<PRIVATE
-
-: (closure) ( obj assoc quot: ( elt -- assoc ) -- )
-    2over key? [
-        3drop
-    ] [
-        2over conjoin [ dip ] keep
-        [ [ drop ] 3dip (closure) ] 2curry assoc-each
-    ] if ; inline recursive
-
-PRIVATE>
-
-: closure ( obj quot -- assoc )
-    H{ } clone [ swap (closure) ] keep ; inline
diff --git a/core/graphs/summary.txt b/core/graphs/summary.txt
deleted file mode 100644 (file)
index aced099..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Directed graphs
diff --git a/core/graphs/tags.txt b/core/graphs/tags.txt
deleted file mode 100644 (file)
index 42d711b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-collections