1
0
Fork 0
This commit is contained in:
Frank Celler 2012-04-25 09:13:13 +02:00
commit 797950b8b7
42 changed files with 615 additions and 202 deletions

View File

@ -1,7 +1,7 @@
avocado> var Graph = require("graph").Graph;
avocado> new Graph(db.vertices, edges.edges);
avocado> new Graph("graph", db.vertices, edges.edges);
Graph("vertices", "edges")
avocado> new Graph("vertices", "edges");
avocado> new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")

View File

@ -1,4 +1,4 @@
avocado> e = g.addEdge(v1, v2, "knows", { weight : 10 });
avocado> e = g.addEdge(v1, v2, null, "knows", { weight : 10 });
Edge(<graph>, "3999653:5570857")
avocado> e.getLabel();

View File

@ -1,7 +1,7 @@
avocado> v = g.addVertex(1);
Vertex(1)
avocado> e = g.addEdge(2, v, v, "self", { "weight" : 10 });
avocado> e = g.addEdge(v, v, 2, "self", { "weight" : 10 });
Edge(2)
avocado> e.getProperty("weight");

View File

@ -1,7 +1,7 @@
avocado> v = g.addVertex();
Vertex(<graph>, "153246:2310672")
avocado> e = g.addEdge(1, v, v, "self");
avocado> e = g.addEdge(v, v, 1, "self");
Edge(1)
avocado> e.getId();

View File

@ -1,7 +1,7 @@
avocado> v = g.addVertex(1);
Vertex(1)
avocado> e = g.addEdge(2, v, v, "self", { weight: 10 })
avocado> e = g.addEdge(v, v, 2, "self", { weight: 10 })
Edge(2)
avocado> e.getPropert("weight")

View File

@ -1,6 +1,6 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:2310672")

View File

@ -1,14 +1,14 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v1 = g.addVertex(null, { name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
avocado> v2 = g.addVertex(null, { name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e = g.addEdge(v1, v2, null, "knows", { "weight" : 10 });
Edge(<graph>, "3999653:7197720")
avocado> v1.inbound();

View File

@ -1,14 +1,14 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v1 = g.addVertex(null, { name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
avocado> v2 = g.addVertex(null, { name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e = g.addEdge(v1, v2, "knows", { "weight" : 10 });
avocado> e = g.addEdge(v1, v2, null, "knows", { "weight" : 10 });
Edge(<graph>, "3999653:7197720")
avocado> v1.outbound();

View File

@ -1,17 +1,17 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graphs", "vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v1 = g.addVertex(null, { name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
avocado> v2 = g.addVertex(null, { name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e1 = g.addEdge(v1, v2, "knows");
avocado> e1 = g.addEdge(v1, v2, null, "knows");
Edge(<graph>, "3999653:7360858")
avocado> e2 = g.addEdge(v1, v2, "hates");
avocado> e2 = g.addEdge(v1, v2, null, "hates");
Edge(<graph>, "3999653:7426394")
avocado> v2.getInEdges();

View File

@ -1,17 +1,17 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
avocado> v1 = g.addVertex({ name : "Hugo" });
avocado> v1 = g.addVertex(null, { name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v2 = g.addVertex({ name : "Emil" });
avocado> v2 = g.addVertex(null, { name : "Emil" });
Vertex(<graph>, "153246:2310673")
avocado> e1 = g.addEdge(v1, v2, "knows");
avocado> e1 = g.addEdge(v1, v2, null, "knows");
Edge(<graph>, "3999653:7360858")
avocado> e2 = g.addEdge(v1, v2, "hates");
avocado> e2 = g.addEdge(v1, v2, null, "hates");
Edge(<graph>, "3999653:7426394")
avocado> v1.getOutEdges();

View File

@ -1,6 +1,6 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v = g.addVertex("hugo");

View File

@ -1,7 +1,7 @@
avocado> v = g.addVertex(1);
Vertex(1)
avocado> e = g.addEdge(2, v, v, "knows");
avocado> e = g.addEdge(v, v, 2, "knows");
Edge(2)
avocado> e.getLabel();

View File

@ -1,7 +1,7 @@
avocado> v1 = g.addVertex(1);
Vertex(1)
avocado> e = g.addEdge(2, v, v, "self");
avocado> e = g.addEdge(v, v, 2, "self");
Edge(2)
avocado> e.getInVertex();

View File

@ -1,7 +1,7 @@
avocado> v = g.addVertex(1);
Vertex(1)
avocado> e = g.addEdge(2, v, v, "self");
avocado> e = g.addEdge(v, v, 2, "self");
Edge(2)
avocado> e.getOutVertex();

View File

@ -1,4 +1,4 @@
avocado> v1.addInEdge("K", v2, "knows");
avocado> v1.addInEdge(v2, "K", "knows");
Edge("K")
avocado> v1.getInEdges();

View File

@ -1,4 +1,4 @@
avocado> v1.addInEdge("D", v2, "knows", { data : 1 });
avocado> v1.addInEdge(v2, "D", "knows", { data : 1 });
Edge("D")
avocado> v1.getInEdges();

View File

@ -1,4 +1,4 @@
avocado> var Graph = require("graph").Graph;
avocado> g1 = new Graph("vertices", "edges");
avocado> g1 = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")

View File

@ -1,4 +1,4 @@
avocado> var Graph = require("graph").Graph;
avocado> g2 = new Graph("vertices", "alternativeEdges");
avocado> g2 = new Graph("graph", "vertices", "alternativeEdges");
Graph("vertices", "alternativeEdges")

View File

@ -1,7 +1,7 @@
avocado> v1 = g.addVertex();
Vertex(<graph>, "153246:8712055")
avocado> v1.addOutEdge(v2, "knows");
avocado> v1.addOutEdge(v2, null, "knows");
Edge(<graph>, "3999653:8974199")
avocado> v1.getOutEdges();

View File

@ -4,7 +4,7 @@ Vertex(<graph>, "153246:8712055")
avocado> v2 = g.addVertex();
Vertex(<graph>, "153246:8777591")
avocado> v1.addOutEdge(v2, "knows", { data : 1 });
avocado> v1.addOutEdge(v2, null, "knows", { data : 1 });
Edge(<graph>, "3999653:8974199")
avocado> v1.getOutEdges();

View File

@ -1,6 +1,6 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> g.addVertex(1);

View File

@ -1,6 +1,6 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex();

View File

@ -1,4 +1,4 @@
avocado> e = g.addEdge(v1, v2, { name : "Emil");
avocado> e = g.addEdge(v1, v2, null, "", { name : "Emil");
Edge(<graph>, "3999653:5570857")
avocado> e.getProperty("name");

View File

@ -1,7 +1,7 @@
avocado> v = g.addVertex(1);
Vertex(1)
avocado> e = g.addEdge(2, v, v, "self", { weight: 10 })
avocado> e = g.addEdge(v, v, 2, "self", { weight: 10 })
Edge(2)
avocado> e.getPropertyKeys()

View File

@ -4,7 +4,7 @@ Vertex(1)
avocado> v2 = g.addVertex(2);
Vertex(2)
avocado> v1.addInEdge("2 -> 1", v2);
avocado> v1.addInEdge(v2, null, "2 -> 1");
Edge("2 -> 1")
avocado> v1.getInEdges();

View File

@ -1,6 +1,6 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex();

View File

@ -1,6 +1,6 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> f = g.getVertices();

View File

@ -1,6 +1,6 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> f = g.getEdges();

View File

@ -1,6 +1,6 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex();

View File

@ -1,6 +1,6 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v1 = g.addVertex();

View File

@ -1,4 +1,4 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")

View File

@ -1,9 +1,9 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v = g.addVertex({ name : "Hugo" });
avocado> v = g.addVertex(null, { name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v.properties();

View File

@ -1,9 +1,9 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v = g.addVertex({ name : "Hugo" });
avocado> v = g.addVertex(null, { name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v.getProperty("name");

View File

@ -1,9 +1,9 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v = g.addVertex({ name : "Hugo" });
avocado> v = g.addVertex(null, { name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v.getProperty("name");

View File

@ -1,9 +1,9 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v = g.addVertex({ name : "Hugo" });
avocado> v = g.addVertex(null, { name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v.getPropertyKeys();

View File

@ -1,9 +1,9 @@
avocado> var Graph = require("graph").Graph;
avocado> g = new Graph("vertices", "edges");
avocado> g = new Graph("graph", "vertices", "edges");
Graph("vertices", "edges")
avocado> v = g.addVertex({ name : "Hugo" });
avocado> v = g.addVertex(null, { name : "Hugo" });
Vertex(<graph>, "153246:2310672")
avocado> v.getId();

View File

@ -1,4 +1,4 @@
avocado> e = g.addEdge(v1, v2, "knows");
avocado> e = g.addEdge(v1, v2, null, "knows");
Edge(<graph>, "3999653:5570857")
avocado> e.getLabel();

View File

@ -1 +1 @@
0.3.12
0.3.13

20
configure vendored
View File

@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.68 for triAGENS AvocadoDB 0.3.12.
# Generated by GNU Autoconf 2.68 for triAGENS AvocadoDB 0.3.13.
#
# Report bugs to <info@triagens.de>.
#
@ -560,8 +560,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='triAGENS AvocadoDB'
PACKAGE_TARNAME='avocado'
PACKAGE_VERSION='0.3.12'
PACKAGE_STRING='triAGENS AvocadoDB 0.3.12'
PACKAGE_VERSION='0.3.13'
PACKAGE_STRING='triAGENS AvocadoDB 0.3.13'
PACKAGE_BUGREPORT='info@triagens.de'
PACKAGE_URL='http://www.avocadodb.org'
@ -1391,7 +1391,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures triAGENS AvocadoDB 0.3.12 to adapt to many kinds of systems.
\`configure' configures triAGENS AvocadoDB 0.3.13 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1462,7 +1462,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of triAGENS AvocadoDB 0.3.12:";;
short | recursive ) echo "Configuration of triAGENS AvocadoDB 0.3.13:";;
esac
cat <<\_ACEOF
@ -1611,7 +1611,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
triAGENS AvocadoDB configure 0.3.12
triAGENS AvocadoDB configure 0.3.13
generated by GNU Autoconf 2.68
Copyright (C) 2010 Free Software Foundation, Inc.
@ -2076,7 +2076,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by triAGENS AvocadoDB $as_me 0.3.12, which was
It was created by triAGENS AvocadoDB $as_me 0.3.13, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ $0 $@
@ -3203,7 +3203,7 @@ fi
# Define the identity of the package.
PACKAGE='avocado'
VERSION='0.3.12'
VERSION='0.3.13'
cat >>confdefs.h <<_ACEOF
@ -10011,7 +10011,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by triAGENS AvocadoDB $as_me 0.3.12, which was
This file was extended by triAGENS AvocadoDB $as_me 0.3.13, which was
generated by GNU Autoconf 2.68. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@ -10078,7 +10078,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
triAGENS AvocadoDB config.status 0.3.12
triAGENS AvocadoDB config.status 0.3.13
configured by $0, generated by GNU Autoconf 2.68,
with options \\"\$ac_cs_config\\"

View File

@ -6,7 +6,7 @@ dnl ============================================================================
dnl PREAMBLE triAGENS GmbH Build Environment
dnl ============================================================================
AC_INIT([triAGENS AvocadoDB], [0.3.12], [info@triagens.de], [avocado], [http://www.avocadodb.org])
AC_INIT([triAGENS AvocadoDB], [0.3.13], [info@triagens.de], [avocado], [http://www.avocadodb.org])
dnl ----------------------------------------------------------------------------
dnl auxillary directory for install-sh and missing

View File

@ -38,7 +38,9 @@ var internal = require("internal"),
AvocadoCollection = internal.AvocadoCollection,
AvocadoEdgesCollection = internal.AvocadoEdgesCollection,
shallowCopy,
propertyKeys;
propertyKeys,
findOrCreateCollectionByName,
findOrCreateEdgeCollectionByName;
// -----------------------------------------------------------------------------
// --SECTION-- private methods
@ -87,6 +89,46 @@ propertyKeys = function (props) {
return keys;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief find or create a collection by name
////////////////////////////////////////////////////////////////////////////////
findOrCreateCollectionByName = function (name) {
var col = internal.db._collection(name);
if (col === null) {
col = internal.db._create(name);
} else if (!(col instanceof AvocadoCollection)) {
throw "<" + name + "> must be a document collection";
}
if (col === null) {
throw "collection '" + name + "' has vanished";
}
return col;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief find or create an edge collection by name
////////////////////////////////////////////////////////////////////////////////
findOrCreateEdgeCollectionByName = function (name) {
var col = internal.edges._collection(name);
if (col === null) {
col = internal.edges._create(name);
} else if (!(col instanceof AvocadoEdgesCollection)) {
throw "<" + name + "> must be a document collection";
}
if (col === null) {
throw "collection '" + name + "' has vanished";
}
return col;
};
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
@ -120,8 +162,7 @@ function Edge(graph, id) {
if (props) {
// extract the custom identifier, label, edges
this._properties = props;
}
else {
} else {
// deleted
throw "accessing a deleted edge";
}
@ -313,16 +354,13 @@ Edge.prototype._PRINT = function (seen, path, names) {
if (!this._id) {
internal.output("[deleted Edge]");
}
else if (this._properties.$id !== undefined) {
} else if (this._properties.$id !== undefined) {
if (typeof this._properties.$id === "string") {
internal.output("Edge(\"", this._properties.$id, "\")");
}
else {
} else {
internal.output("Edge(", this._properties.$id, ")");
}
}
else {
} else {
internal.output("Edge(<", this._id, ">)");
}
};
@ -359,8 +397,7 @@ function Vertex(graph, id) {
if (props) {
// extract the custom identifier
this._properties = props;
}
else {
} else {
// deleted
throw "accessing a deleted edge";
}
@ -382,17 +419,17 @@ function Vertex(graph, id) {
////////////////////////////////////////////////////////////////////////////////
/// @brief adds an inbound edge
///
/// @FUN{@FA{vertex}.addInEdge(@FA{id}, @FA{peer})}
/// @FUN{@FA{vertex}.addInEdge(@FA{peer}, @FA{id})}
///
/// Creates a new edge from @FA{peer} to @FA{vertex} and returns the edge
/// object. The identifier @FA{id} must be a unique identifier or null.
///
/// @FUN{@FA{vertex}.addInEdge(@FA{id}, @FA{peer}, @FA{label})}
/// @FUN{@FA{vertex}.addInEdge(@FA{peer}, @FA{id}, @FA{label})}
///
/// Creates a new edge from @FA{peer} to @FA{vertex} with given label and
/// returns the edge object.
///
/// @FUN{@FA{vertex}.addInEdge(@FA{id}, @FA{peer}, @FA{label}, @FA{data})}
/// @FUN{@FA{vertex}.addInEdge(@FA{peer}, @FA{id}, @FA{label}, @FA{data})}
///
/// Creates a new edge from @FA{peer} to @FA{vertex} with given label and
/// properties defined in @FA{data}. Returns the edge object.
@ -406,8 +443,8 @@ function Vertex(graph, id) {
/// @verbinclude graph24
////////////////////////////////////////////////////////////////////////////////
Vertex.prototype.addInEdge = function (id, out, label, data) {
return this._graph.addEdge(id, out, this, label, data);
Vertex.prototype.addInEdge = function (out, id, label, data) {
return this._graph.addEdge(out, this, id, label, data);
};
////////////////////////////////////////////////////////////////////////////////
@ -437,8 +474,8 @@ Vertex.prototype.addInEdge = function (id, out, label, data) {
/// @verbinclude graph28
////////////////////////////////////////////////////////////////////////////////
Vertex.prototype.addOutEdge = function (id, ine, label, data) {
return this._graph.addEdge(id, this, ine, label, data);
Vertex.prototype.addOutEdge = function (ine, id, label, data) {
return this._graph.addEdge(this, ine, id, label, data);
};
////////////////////////////////////////////////////////////////////////////////
@ -507,8 +544,7 @@ Vertex.prototype.getInEdges = function () {
if (arguments.length === 0) {
result = this.inbound();
}
else {
} else {
labels = {};
for (i = 0; i < arguments.length; ++i) {
@ -547,8 +583,7 @@ Vertex.prototype.getOutEdges = function () {
if (arguments.length === 0) {
result = this.outbound();
}
else {
} else {
labels = {};
for (i = 0; i < arguments.length; ++i) {
labels[arguments[i]] = true;
@ -731,16 +766,13 @@ Vertex.prototype._PRINT = function (seen, path, names) {
if (!this._id) {
internal.output("[deleted Vertex]");
}
else if (this._properties.$id !== undefined) {
} else if (this._properties.$id !== undefined) {
if (typeof this._properties.$id === "string") {
internal.output("Vertex(\"", this._properties.$id, "\")");
}
else {
} else {
internal.output("Vertex(", this._properties.$id, ")");
}
}
else {
} else {
internal.output("Vertex(<", this._id, ">)");
}
};
@ -781,123 +813,93 @@ Vertex.prototype._PRINT = function (seen, path, names) {
/// @verbinclude graph1
////////////////////////////////////////////////////////////////////////////////
function Graph (name, vertices, edges) {
var gdb;
var col;
var props;
function Graph(name, vertices, edges) {
var gdb,
graphProperties,
graphPropertiesId,
optionsForGraphCreation;
gdb = internal.db._collection("_graph");
if (gdb === null) {
gdb = internal.db._create("_graph", { waitForSync : true, isSystem : true });
optionsForGraphCreation = { waitForSync : true, isSystem : true };
gdb = internal.db._create("_graph", optionsForGraphCreation);
// gdb.ensureUniqueConstraint("name");
}
// @FUN{Graph(@FA{name})}
if (vertices === undefined && edges == undefined) {
props = gdb.firstExample('name', name);
if (props === null) {
throw "no graph named '" + name + "' found";
}
vertices = internal.db._collection(props.vertices);
if (vertices == null) {
throw "vertex collection '" + props.vertices + "' has vanished";
}
edges = internal.edges._collection(props.edges);
if (edges == null) {
throw "edge collection '" + props.edges + "' has vanished";
}
}
// @FUN{Graph(@FA{name}, @FA{vertices}, @FA{edges})}
else {
// get the vertices collection
if (typeof vertices === "string") {
col = internal.db._collection(vertices);
if (col === null) {
col = internal.db._create(vertices);
}
if (col == null) {
throw "vertex collection '" + vertices + "' has vanished";
}
// col.ensureUniqueConstraint("$id");
vertices = col;
}
// get the edges collection
if (typeof edges === "string") {
col = internal.edges._collection(edges);
if (col === null) {
col = internal.edges._create(edges);
}
if (col == null) {
throw "edge collection '" + edges + "' has vanished";
}
// col.ensureUniqueConstraint("$id");
edges = col;
}
// find graph by name
if (typeof name !== "string" || name === "") {
throw "<name> must be a string";
}
props = gdb.firstExample('name', name);
if (vertices === undefined && edges === undefined) {
// Find an existing graph
// name is unknown
if (props === null) {
graphProperties = gdb.firstExample('name', name);
if (graphProperties === null) {
throw "no graph named '" + name + "' found";
}
vertices = internal.db._collection(graphProperties.vertices);
if (vertices === null) {
throw "vertex collection '" + graphProperties.vertices + "' has vanished";
}
edges = internal.edges._collection(graphProperties.edges);
if (edges === null) {
throw "edge collection '" + graphProperties.edges + "' has vanished";
}
} else if (typeof vertices !== "string" || vertices === "") {
throw "<vertices> must be a string or null";
} else if (typeof edges !== "string" || edges === "") {
throw "<edges> must be a string or null";
} else {
// Create a new graph or get an existing graph
vertices = findOrCreateCollectionByName(vertices);
edges = findOrCreateEdgeCollectionByName(edges);
// Currently buggy:
// edges.ensureUniqueConstraint("$id");
// vertices.ensureUniqueConstraint("$id");
graphProperties = gdb.firstExample('name', name);
if (graphProperties === null) {
// Graph doesn't exist yet
// check if know that graph
props = gdb.firstExample('vertices', vertices._id, 'edges', edges._id);
graphProperties = gdb.firstExample('vertices',
vertices._id,
'edges',
edges._id
);
if (props === null) {
d = gdb.save({ 'vertices' : vertices._id,
if (graphProperties === null) {
graphPropertiesId = gdb.save({ 'vertices' : vertices._id,
'verticesName' : vertices.name(),
'edges' : edges._id,
'edgesName' : edges.name(),
'name' : name });
props = gdb.document(d);
}
else {
graphProperties = gdb.document(graphPropertiesId);
} else {
throw "found graph but has different <name>";
}
}
else {
if (props.vertices !== vertices._id) {
} else {
if (graphProperties.vertices !== vertices._id) {
throw "found graph but has different <vertices>";
}
if (props.edges !== edges._id) {
if (graphProperties.edges !== edges._id) {
throw "found graph but has different <edges>";
}
}
}
if (! (vertices instanceof AvocadoCollection)) {
throw "<vertices> must be a document collection";
}
if (! (edges instanceof AvocadoEdgesCollection)) {
throw "<edges> must be an edges collection";
}
this._properties = props;
this._properties = graphProperties;
// and store the collections
this._vertices = vertices;
@ -938,27 +940,27 @@ Graph.prototype.drop = function () {
this._vertices.drop();
this._edges.drop();
}
};
////////////////////////////////////////////////////////////////////////////////
/// @brief adds an edge to the graph
///
/// @FUN{@FA{graph}.addEdge(@FA{id}, @FA{out}, @FA{in})}
/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id})}
///
/// Creates a new edge from @FA{out} to @FA{in} and returns the edge object. The
/// identifier @FA{id} must be a unique identifier or null.
///
/// @FUN{@FA{graph}.addEdge(@FA{id}, @FA{out}, @FA{in}, @FA{label})}
/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id}, @FA{label})}
///
/// Creates a new edge from @FA{out} to @FA{in} with @FA{label} and returns the
/// edge object.
///
/// @FUN{@FA{graph}.addEdge(@FA{id}, @FA{out}, @FA{in}, @FA{data})}
/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id}, @FA{data})}
///
/// Creates a new edge and returns the edge object. The edge contains the
/// properties defined in @FA{data}.
///
/// @FUN{@FA{graph}.addEdge(@FA{id}, @FA{out}, @FA{in}, @FA{label}, @FA{data})}
/// @FUN{@FA{graph}.addEdge(@FA{out}, @FA{in}, @FA{id}, @FA{label}, @FA{data})}
///
/// Creates a new edge and returns the edge object. The edge has the
/// label @FA{label} and contains the properties defined in @FA{data}.
@ -974,7 +976,7 @@ Graph.prototype.drop = function () {
/// @verbinclude graph10
////////////////////////////////////////////////////////////////////////////////
Graph.prototype.addEdge = function (id, out, ine, label, data) {
Graph.prototype.addEdge = function (out_vertex, in_vertex, id, label, data) {
var ref,
shallow;
@ -996,7 +998,7 @@ Graph.prototype.addEdge = function (id, out, ine, label, data) {
shallow.$id = id || null;
shallow.$label = label || null;
ref = this._edges.save(out._id, ine._id, shallow);
ref = this._edges.save(out_vertex._id, in_vertex._id, shallow);
return this.constructEdge(ref._id);
};
@ -1062,8 +1064,7 @@ Graph.prototype.getVertex = function (id) {
if (ref !== null) {
vertex = this.constructVertex(ref._id);
}
else {
} else {
vertex = null;
}
@ -1262,7 +1263,7 @@ Graph.prototype.constructVertex = function (id) {
Graph.prototype.constructEdge = function (id) {
var edge = this._weakEdges[id];
if (edge === null) {
if (edge === undefined) {
this._weakEdges[id] = edge = new Edge(this, id);
}
@ -1310,5 +1311,6 @@ exports.Vertex = Vertex;
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
// outline-regexp:
// "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
// End:

View File

@ -1,7 +1,13 @@
/*jslint indent: 2,
nomen: true,
maxlen: 80 */
/*global require, db, assertEqual */
/*global require,
db,
assertEqual, assertTrue,
print,
PRINT_OBJECT,
console,
AvocadoCollection, AvocadoEdgesCollection */
(function () {
"use strict";
@ -38,17 +44,69 @@
// --SECTION-- collection methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite: Graph Creation
////////////////////////////////////////////////////////////////////////////////
function graphCreationSuite() {
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief test: Graph Creation
////////////////////////////////////////////////////////////////////////////////
testCreation: function () {
var Graph = require("graph").Graph,
graph_name = "UnitTestsCollectionGraph",
vertex = "UnitTestsCollectionVertex",
edge = "UnitTestsCollectionEdge",
graph = null;
graph = new Graph(graph_name, vertex, edge);
assertEqual(graph_name, graph._properties.name);
assertTrue(graph._vertices instanceof AvocadoCollection);
assertTrue(graph._edges instanceof AvocadoEdgesCollection);
graph.drop();
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: Find Graph
////////////////////////////////////////////////////////////////////////////////
testFindGraph: function () {
var Graph = require("graph").Graph,
graph_name = "UnitTestsCollectionGraph",
vertex = "UnitTestsCollectionVertex",
edge = "UnitTestsCollectionEdge",
graph1 = null,
graph2 = null;
graph1 = new Graph(graph_name, vertex, edge);
graph2 = new Graph(graph_name);
assertEqual(graph1._properties.name, graph2._properties.name);
assertEqual(graph1._vertices, graph2._vertices);
assertEqual(graph1._edges, graph2._edges);
graph1.drop();
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite: Graph Basics
////////////////////////////////////////////////////////////////////////////////
function graphBasicsSuite() {
//var ERRORS = require("internal").errors;
var Graph = require("graph").Graph;
var graph_name = "UnitTestsCollectionGraph";
var vertex = "UnitTestsCollectionVertex";
var edge = "UnitTestsCollectionEdge";
var graph = null;
var Graph = require("graph").Graph,
graph_name = "UnitTestsCollectionGraph",
vertex = "UnitTestsCollectionVertex",
edge = "UnitTestsCollectionEdge",
graph = null;
return {
@ -63,14 +121,12 @@
print("FOUND: ");
PRINT_OBJECT(graph);
graph.drop();
}
catch (err) {
} catch (err1) {
}
graph = new Graph(graph_name, vertex, edge);
}
catch (err) {
console.error("[FAILED] setup failed:" + err);
} catch (err2) {
console.error("[FAILED] setup failed:" + err2);
}
},
@ -80,11 +136,10 @@
tearDown : function () {
try {
if (graph != null) {
if (graph !== null) {
graph.drop();
}
}
catch (err) {
} catch (err) {
console.error("[FAILED] tear-down failed:" + err);
}
},
@ -138,15 +193,371 @@
assertEqual("name2", v.getId());
assertEqual(23, v.getProperty("age"));
},
////////////////////////////////////////////////////////////////////////////////
/// @brief change a property
////////////////////////////////////////////////////////////////////////////////
testAddEdgeWithoutInfo : function () {
var v1,
v2,
edge;
v1 = graph.addVertex("vertex1");
v2 = graph.addVertex("vertex2");
edge = graph.addEdge(v1,
v2);
assertEqual(null, edge.getId());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief change a property
////////////////////////////////////////////////////////////////////////////////
testAddEdge : function () {
var v1,
v2,
edge;
v1 = graph.addVertex("vertex1");
v2 = graph.addVertex("vertex2");
edge = graph.addEdge(v1,
v2,
"edge1",
"label",
{ testProperty: "testValue" });
assertEqual("edge1", edge.getId());
assertEqual("label", edge.getLabel());
assertEqual("testValue", edge.getProperty("testProperty"));
},
////////////////////////////////////////////////////////////////////////////////
/// @brief change a property
////////////////////////////////////////////////////////////////////////////////
testGetEdges : function () {
var v1,
v2,
edge1,
edge2;
v1 = graph.addVertex("vertex1");
v2 = graph.addVertex("vertex2");
edge1 = graph.addEdge(v1,
v2,
"edge1",
"label",
{ testProperty: "testValue" });
edge2 = graph.getEdges().next();
assertEqual(true, graph.getEdges().hasNext());
assertEqual(edge1.getId(), edge2.getId());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief remove an edge
////////////////////////////////////////////////////////////////////////////////
testRemoveEdges : function () {
var v1,
v2,
edge;
v1 = graph.addVertex("vertex1");
v2 = graph.addVertex("vertex2");
edge = graph.addEdge(v1,
v2,
"edge1",
"label",
{ testProperty: "testValue" });
graph.removeEdge(edge);
assertEqual(false, graph.getEdges().hasNext());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief remove a vertex
////////////////////////////////////////////////////////////////////////////////
testRemoveVertex : function () {
var v1,
v1_id,
v2,
edge;
v1 = graph.addVertex("vertex1");
v1_id = v1.getId();
v2 = graph.addVertex("vertex2");
edge = graph.addEdge(v1,
v2,
"edge1",
"label",
{ testProperty: "testValue" });
graph.removeVertex(v1);
assertEqual(null, graph.getVertex(v1_id));
assertEqual(false, graph.getEdges().hasNext());
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite: Vertex
////////////////////////////////////////////////////////////////////////////////
function vertexSuite() {
var Graph = require("graph").Graph,
graph_name = "UnitTestsCollectionGraph",
vertex = "UnitTestsCollectionVertex",
edge = "UnitTestsCollectionEdge",
graph = null;
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
try {
try {
graph = new Graph(graph_name);
print("FOUND: ");
PRINT_OBJECT(graph);
graph.drop();
} catch (err1) {
}
graph = new Graph(graph_name, vertex, edge);
} catch (err2) {
console.error("[FAILED] setup failed:" + err2);
}
},
////////////////////////////////////////////////////////////////////////////////
/// @brief tear down
////////////////////////////////////////////////////////////////////////////////
tearDown : function () {
try {
if (graph !== null) {
graph.drop();
}
} catch (err) {
console.error("[FAILED] tear-down failed:" + err);
}
},
////////////////////////////////////////////////////////////////////////////////
/// @brief add edges
////////////////////////////////////////////////////////////////////////////////
testAddEdges : function () {
var v1,
v2,
v3,
edge1,
edge2;
v1 = graph.addVertex(graph);
v2 = graph.addVertex(graph);
v3 = graph.addVertex(graph);
edge1 = v1.addInEdge(v2);
edge2 = v1.addOutEdge(v3);
assertEqual(v1.getId(), edge1.getInVertex().getId());
assertEqual(v2.getId(), edge1.getOutVertex().getId());
assertEqual(v3.getId(), edge2.getInVertex().getId());
assertEqual(v1.getId(), edge2.getOutVertex().getId());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief get edges
////////////////////////////////////////////////////////////////////////////////
testGetEdges : function () {
var v1,
v2,
edge;
v1 = graph.addVertex(graph);
v2 = graph.addVertex(graph);
edge = graph.addEdge(v1, v2);
assertEqual(edge.getId(), v1.getOutEdges()[0].getId());
assertEqual(edge.getId(), v2.getInEdges()[0].getId());
assertEqual([], v1.getInEdges());
assertEqual([], v2.getOutEdges());
assertEqual(edge.getId(), v1.edges()[0].getId());
assertEqual(edge.getId(), v2.edges()[0].getId());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief get edges with labels
////////////////////////////////////////////////////////////////////////////////
testGetEdgesWithLabels : function () {
var v1,
v2,
edge1,
edge2;
v1 = graph.addVertex(graph);
v2 = graph.addVertex(graph);
edge1 = graph.addEdge(v1, v2, null, "label_1");
edge2 = graph.addEdge(v1, v2, null, "label_2");
assertEqual(edge2.getId(), v1.getOutEdges("label_2")[0].getId());
assertEqual(1, v2.getInEdges("label_2").length);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief properties
////////////////////////////////////////////////////////////////////////////////
testProperties : function () {
var v1;
v1 = graph.addVertex(graph);
v1.setProperty("myProperty", "myValue");
assertEqual("myValue", v1.getProperty("myProperty"));
assertEqual("myProperty", v1.getPropertyKeys()[0]);
assertEqual(1, v1.getPropertyKeys().length);
assertEqual({myProperty: "myValue"}, v1.properties());
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite: Edges
////////////////////////////////////////////////////////////////////////////////
function edgeSuite() {
var Graph = require("graph").Graph,
graph_name = "UnitTestsCollectionGraph",
vertex = "UnitTestsCollectionVertex",
edge = "UnitTestsCollectionEdge",
graph = null;
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
try {
try {
graph = new Graph(graph_name);
print("FOUND: ");
PRINT_OBJECT(graph);
graph.drop();
} catch (err1) {
}
graph = new Graph(graph_name, vertex, edge);
} catch (err2) {
console.error("[FAILED] setup failed:" + err2);
}
},
////////////////////////////////////////////////////////////////////////////////
/// @brief tear down
////////////////////////////////////////////////////////////////////////////////
tearDown : function () {
try {
if (graph !== null) {
graph.drop();
}
} catch (err) {
console.error("[FAILED] tear-down failed:" + err);
}
},
////////////////////////////////////////////////////////////////////////////////
/// @brief get Vertices
////////////////////////////////////////////////////////////////////////////////
testGetVertices : function () {
var v1,
v2,
edge;
v1 = graph.addVertex();
v2 = graph.addVertex();
edge = graph.addEdge(v1, v2);
assertEqual(v1.getId(), edge.getInVertex().getId());
assertEqual(v2.getId(), edge.getOutVertex().getId());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief get Vertices
////////////////////////////////////////////////////////////////////////////////
testGetLabel : function () {
var v1,
v2,
edge;
v1 = graph.addVertex();
v2 = graph.addVertex();
edge = graph.addEdge(v1, v2, null, "my_label");
assertEqual("my_label", edge.getLabel());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief Properties
////////////////////////////////////////////////////////////////////////////////
testProperties : function () {
var v1,
v2,
edge,
properties;
v1 = graph.addVertex();
v2 = graph.addVertex();
properties = { myProperty: "myValue"};
edge = graph.addEdge(v1, v2, null, "my_label", properties);
assertEqual(properties, edge.properties());
assertEqual("myValue", edge.getProperty("myProperty"));
edge.setProperty("foo", "bar");
assertEqual("bar", edge.getProperty("foo"));
assertEqual(["foo", "myProperty"], edge.getPropertyKeys());
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief executes the test suites
////////////////////////////////////////////////////////////////////////////////
jsunity.run(graphCreationSuite);
jsunity.run(graphBasicsSuite);
jsunity.run(vertexSuite);
jsunity.run(edgeSuite);
jsunity.done();
}());