dangraph / Exports / undirected_graph/danUndirectedGraph / DanUndirectedGraph
undirected_graph/danUndirectedGraph.DanUndirectedGraph
The DanUndirectedGraph class handles undirected graphs
| Name |
|---|
I |
D |
- _checkForCycle
- _getANode
- _getAdjacentNodesList
- _getCopyOfInnerGraph
- _visitNodes
- addArcToNode
- addArcToNodeId
- addNode
- countNodes
- getNodeAndUndirectedArcsFromNodeId
- hasNodeId
- isAcyclic
- isConnected
- isEmpty
- removeNode
- toString
- generateConsecutiveNodeGraph
- generateRandomNodeGraph
• new DanUndirectedGraph<I, D>(): DanUndirectedGraph<I, D>
the public class constructor
| Name |
|---|
I |
D |
DanUndirectedGraph<I, D>
src/undirected_graph/danUndirectedGraph.ts:28
• Protected _graph: Map<I, DanNodeAndUndirectedArcs<I, D>>
src/undirected_graph/danUndirectedGraph.ts:23
▸ _checkForCycle(visitedNodes, nextNode, fromNode?): boolean
Recursively checks for the presence of a cycle starting from node id nextNode
| Name | Type | Default value | Description |
|---|---|---|---|
visitedNodes |
Set<I> |
undefined |
the nodes already visited |
nextNode |
I |
undefined |
the next node to visit |
fromNode |
undefined | I |
undefined |
the parent node (default: undefined) |
boolean
true if a cycle is found, false if no cycle is found
src/undirected_graph/danUndirectedGraph.ts:217
▸ _getANode(): undefined | DanNode<I, D>
Get a node in the graph
undefined | DanNode<I, D>
a node in the graph or undefined if the graph is empty
src/undirected_graph/danUndirectedGraph.ts:186
▸ _getAdjacentNodesList(idNode): DanNode<I, D>[]
Get the list of adjacent nodes of a given node identifier
| Name | Type | Description |
|---|---|---|
idNode |
I |
the id of the node to check |
DanNode<I, D>[]
the list of adjacent nodes of idNode as array of DanNode<I, D>
src/undirected_graph/danUndirectedGraph.ts:167
▸ _getCopyOfInnerGraph(): Map<I, DanNodeAndUndirectedArcs<I, D>>
Clone the inner graph structure
Map<I, DanNodeAndUndirectedArcs<I, D>>
a copy of the inner graph structure
src/undirected_graph/danUndirectedGraph.ts:310
▸ _visitNodes(visitedNodes, nextNode): void
Protected method to visit all the neighbours of a node, given in input the node id and a previous set of visitedNodes
| Name | Type | Description |
|---|---|---|
visitedNodes |
Set<I> |
the nodes already visited |
nextNode |
I |
the next node to visit |
void
src/undirected_graph/danUndirectedGraph.ts:200
▸ addArcToNode(node, arcToAdd): boolean
Add arc to node, given the node interface structure
| Name | Type | Description |
|---|---|---|
node |
DanNode<I, D> |
the node receiving arcToAdd |
arcToAdd |
DanArc<I, D> |
- |
boolean
true if arcToAdd was correctly added to the adjacent arcs of node; false if arcToAdd was already present
src/undirected_graph/danUndirectedGraph.ts:134
▸ addArcToNodeId(idNode, arcToAdd): boolean
Add an arc to a node, given the node identifier
| Name | Type | Description |
|---|---|---|
idNode |
I |
the id of the node receiving arcToAdd |
arcToAdd |
DanArc<I, D> |
the arc being added |
boolean
true if arcToAdd was correctly added to the adjacent arcs of idNode; false if the idNode does not exist or if arcToAdd was already present
src/undirected_graph/danUndirectedGraph.ts:98
▸ addNode(node): boolean
Add a node to the graph
| Name | Type | Description |
|---|---|---|
node |
DanNode<I, D> |
the node to add |
boolean
true if the node was correctly added to the graph; false if the node is already present
src/undirected_graph/danUndirectedGraph.ts:81
▸ countNodes(): number
Public method to retrieve the number of nodes in the graph
number
the number of nodes in the graph
src/undirected_graph/danUndirectedGraph.ts:273
▸ getNodeAndUndirectedArcsFromNodeId(idNode): undefined | DanNodeAndUndirectedArcs<I, D>
Get node and undirected arcs structure (as DanNodeAndUndirectedArcs) from nodeId
| Name | Type | Description |
|---|---|---|
idNode |
I |
the node identifier |
undefined | DanNodeAndUndirectedArcs<I, D>
node and undirected arcs structure or undefined if nodeId is not present in the graph
src/undirected_graph/danUndirectedGraph.ts:319
▸ hasNodeId(idNode): boolean
Check if idNode is present in the graph
| Name | Type | Description |
|---|---|---|
idNode |
I |
the id of the node |
boolean
true only if idNode is present
src/undirected_graph/danUndirectedGraph.ts:328
▸ isAcyclic(): boolean
Public method to check if the graph is acyclic
boolean
true if the graph does not contain cycles
src/undirected_graph/danUndirectedGraph.ts:253
▸ isConnected(): boolean
Check if the graph is connected
boolean
true if the graph is connected
src/undirected_graph/danUndirectedGraph.ts:240
▸ isEmpty(): boolean
Check if the graph is empty
boolean
true if the graph does not contain any node
src/undirected_graph/danUndirectedGraph.ts:281
▸ removeNode(idNode): boolean
Remove the node given in input from the graph
| Name | Type | Description |
|---|---|---|
idNode |
I |
the id of the node to remove |
boolean
true if the node is correctly removed
src/undirected_graph/danUndirectedGraph.ts:147
▸ toString(showArcDetails?): string
The string representation of the undirected graph
| Name | Type | Default value |
|---|---|---|
showArcDetails |
boolean |
false |
string
the string representation of the undirected graph
src/undirected_graph/danUndirectedGraph.ts:290
▸ generateConsecutiveNodeGraph(numOfNodes): DanUndirectedGraph<number, undefined>
A utility public static method to generate an undirected graph with a number of numOfNodes consecutive nodes
| Name | Type | Description |
|---|---|---|
numOfNodes |
number |
the number of nodes of the output graph |
DanUndirectedGraph<number, undefined>
an undirected graph witn numOfNodes nodes
src/undirected_graph/danUndirectedGraph.ts:37
▸ generateRandomNodeGraph(numOfNodes): DanUndirectedGraph<number, undefined>
A utility public static method to generate an undirected graph with a number of numOfNodes random nodes
| Name | Type | Description |
|---|---|---|
numOfNodes |
number |
the number of nodes of the output graph |
DanUndirectedGraph<number, undefined>
an undirected graph witn numOfNodes nodes