ARCcore.graph's DirectedGraph
container class provides a normalized API for
managing in-memory directed graph data structures regardless of the application-specific semantics you ascribe to the vertices
and directed edge relationships you store in the container. And, regardless of any optional property data attached to the vertices
and edges.
Many data structures are simply modeled using directed graphs making DirectedGraph
an attractive solution
for managing run-time data in many common situations.
Consider storing your application-specific data structures as directed graphs and passing around DirectedGraph
container
references instead of JavaScript object references to avoid serialization problems.
Use of DirectedGraph
in your derived library and application code allows you to:
See also: Serialization
DirectedGraph
, is constructed by calling the arccore.graph.directed.create
factory function export.
const graph = require('arccore').graph;
var response = graph.directed.create(/*optional init data*/);
if (!response.error) {
// container is ready for use
var digraph = response.result;
console.log("digraph JSON = '" + digraph.stringify() + "'");
} else {
// container constructor failed
console.error(response.error);
}
If the DirectedGraph
container is successfully constructed, graph.directed.create
returns a response object that looks like this:
{ error: null, result: DirectedGraph }
However, if you call graph.directed.create
passing an input parameter to the digraph factory that is invalid the response object looks like this:
{ error: "Some error string explaining what went wrong.", result: null }
It is essential that you check and ensure that response.error === null
before using response.result
.
In the example above, we're actually being verbose; this won't ever fail (tests ensure that). But, that's not the general case where
you're likely to be constructing a new DirectedGraph
instance from serialized data.
Here's a dump of DirectedGraph
class methods. Scroll down to the bottom of this page for links to in-depth discussion and references for each method.
$ node
> const arccore = require('arccore');
undefined
> var digraph = arccore.graph.directed.create().result;
undefined
> digraph
DirectedGraph {
getGraphName: [Function],
setGraphName: [Function],
getGraphDescription: [Function],
setGraphDescription: [Function],
isVertex: [Function],
addVertex: [Function],
removeVertex: [Function],
getVertexProperty: [Function],
setVertexProperty: [Function],
hasVertexProperty: [Function],
clearVertexProperty: [Function],
inDegree: [Function],
inEdges: [Function],
outDegree: [Function],
outEdges: [Function],
isEdge: [Function],
addEdge: [Function],
removeEdge: [Function],
getEdgeProperty: [Function],
setEdgeProperty: [Function],
hasEdgeProperty: [Function],
clearEdgeProperty: [Function],
verticesCount: [Function],
getVertices: [Function],
edgesCount: [Function],
getEdges: [Function],
rootVerticesCount: [Function],
getRootVertices: [Function],
leafVerticesCount: [Function],
getLeafVertices: [Function],
toJSON: [Function],
toObject: [Function],
stringify: [Function],
fromObject: [Function],
fromJSON: [Function],
_private:
{ name: '',
description: '',
vertexMap: {},
rootMap: {},
leafMap: {},
edgeCount: 0,
constructionError: null } }
>