Link Search Menu Expand Document

Utilities

#.copy

Returns a copy of the current instance.

Example

graph.addNodesFrom(['Thomas', 'Eric']);
graph.addEdgeWithKey('T->E', 'Thomas', 'Eric', {type: 'KNOWS'});

const newGraph = graph.copy();
newGraph.hasNode('Eric');
>>> true
newGraph.order
>>> 2
newGraph.size
>>> 1
graph.type === newGraph.type
>>> true

#.nullCopy

Returns a null copy, i.e. a copy of the graph without nodes nor edges, of the current instance while retaining the type & the options of the graph.

Example

graph.addNodesFrom(['Thomas', 'Eric']);
graph.addEdgeWithKey('T->E', 'Thomas', 'Eric', {type: 'KNOWS'});

const newGraph = graph.nullCopy();
newGraph.hasNode('Eric');
>>> false
newGraph.order
>>> 0
newGraph.size
>>> 0
graph.type === newGraph.type
>>> true

Arguments

  • options [object]: options to merge to create a slightly different graph.

#.emptyCopy

Returns an empty copy, i.e. a copy of the graph containing only nodes, of the current instance while retaining the type & the options of the graph.

This is useful to functions needing to return subgraphs or near identical copies of a graph such as reversed graph or graph converted to another type altogether.

Example

graph.addNodesFrom(['Thomas', 'Eric']);
graph.addEdgeWithKey('T->E', 'Thomas', 'Eric', {type: 'KNOWS'});

const newGraph = graph.emptyCopy();
newGraph.hasNode('Eric');
>>> true
newGraph.order
>>> 2
newGraph.size
>>> 0
newGraph.hasEdge('Thomas', 'Eric');
>>> false
graph.type === newGraph.type
>>> true

Arguments

  • options [object]: options to merge to create a slightly different graph.