Members
edges
Returns number of edges in the graph
size
Returns number of nodes in the graph
Methods
addEdge(nodeA, nodeB, weightopt)
Adds a new edge between two nodes
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
nodeA |
number | string | |||
nodeB |
number | string | |||
weight |
any |
<optional> |
1 | Optional, default 1 if not provided |
addNode(id, valopt)
Adds a new node to the graph
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
id |
number | string | ||
val |
any |
<optional> |
getNode(id) → {any}
Returns value of node
Parameters:
Name | Type | Description |
---|---|---|
id |
number | string |
Returns:
- Value
- Type
- any
getPath(nodeA, nodeB) → {Array.<Array>}
Returns array of the shortest path between two nodes
Based on the shortest number of intermediate nodes
Parameters:
Name | Type | Description |
---|---|---|
nodeA |
number | string | |
nodeB |
number | string |
Returns:
- [{node, weight}]
- Type
- Array.<Array>
getPathWeighted(nodeA, nodeB) → {Array.<Array>}
Returns array of the shortest weighted path between two nodes (Dijkstra algorithm)
Based on the shortest number of intermediate nodes
Parameters:
Name | Type | Description |
---|---|---|
nodeA |
number | string | |
nodeB |
number | string |
Returns:
- [{nodes: [], distance: number}]
- Type
- Array.<Array>
getWeight(nodeA, nodeB) → {number}
Returns the sum of weights between two nodes, including intermediate ones.
Based on the shortest number of intermediate nodes
Parameters:
Name | Type | Description |
---|---|---|
nodeA |
number | string | |
nodeB |
number | string |
Returns:
- Type
- number
nodesConnected(nodeA, nodeB) → {boolean}
Returns true/false if edge exists between two nodes
Parameters:
Name | Type | Description |
---|---|---|
nodeA |
number | string | |
nodeB |
number | string |
Returns:
- True/False if connection exists between nodes
- Type
- boolean
removeEdge(nodeA, nodeB) → {boolean}
Removes an existing edge between two nodes
Parameters:
Name | Type | Description |
---|---|---|
nodeA |
number | string | |
nodeB |
number | string |
Returns:
- Type
- boolean
removeNode(id) → {boolean}
Remove the node, and its edges across all the nodes
Parameters:
Name | Type | Description |
---|---|---|
id |
number | string |
Returns:
- Type
- boolean
updateEdge(nodeA, nodeB, weightopt) → {boolean}
Updates the weight of an existing edge between two nodes
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
nodeA |
number | string | |||
nodeB |
number | string | |||
weight |
weight |
<optional> |
1 | Optional, default 1 if not provided |
Returns:
- Type
- boolean
updateNode(id, valopt) → {boolean}
Updates value for an existing node
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
id |
number | string | ||
val |
any |
<optional> |
Returns:
- Type
- boolean