Skip to content

Latest commit

 

History

History
477 lines (265 loc) · 13.3 KB

File metadata and controls

477 lines (265 loc) · 13.3 KB

dangraph / Exports / undirected_graph/danUndirectedGraph / DanUndirectedGraph

Class: DanUndirectedGraph<I, D>

undirected_graph/danUndirectedGraph.DanUndirectedGraph

The DanUndirectedGraph class handles undirected graphs

Type parameters

Name
I
D

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new DanUndirectedGraph<I, D>(): DanUndirectedGraph<I, D>

the public class constructor

Type parameters

Name
I
D

Returns

DanUndirectedGraph<I, D>

Defined in

src/undirected_graph/danUndirectedGraph.ts:28

Properties

_graph

Protected _graph: Map<I, DanNodeAndUndirectedArcs<I, D>>

Defined in

src/undirected_graph/danUndirectedGraph.ts:23

Methods

_checkForCycle

_checkForCycle(visitedNodes, nextNode, fromNode?): boolean

Recursively checks for the presence of a cycle starting from node id nextNode

Parameters

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)

Returns

boolean

true if a cycle is found, false if no cycle is found

Defined in

src/undirected_graph/danUndirectedGraph.ts:217


_getANode

_getANode(): undefined | DanNode<I, D>

Get a node in the graph

Returns

undefined | DanNode<I, D>

a node in the graph or undefined if the graph is empty

Defined in

src/undirected_graph/danUndirectedGraph.ts:186


_getAdjacentNodesList

_getAdjacentNodesList(idNode): DanNode<I, D>[]

Get the list of adjacent nodes of a given node identifier

Parameters

Name Type Description
idNode I the id of the node to check

Returns

DanNode<I, D>[]

the list of adjacent nodes of idNode as array of DanNode<I, D>

Defined in

src/undirected_graph/danUndirectedGraph.ts:167


_getCopyOfInnerGraph

_getCopyOfInnerGraph(): Map<I, DanNodeAndUndirectedArcs<I, D>>

Clone the inner graph structure

Returns

Map<I, DanNodeAndUndirectedArcs<I, D>>

a copy of the inner graph structure

Defined in

src/undirected_graph/danUndirectedGraph.ts:310


_visitNodes

_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

Parameters

Name Type Description
visitedNodes Set<I> the nodes already visited
nextNode I the next node to visit

Returns

void

Defined in

src/undirected_graph/danUndirectedGraph.ts:200


addArcToNode

addArcToNode(node, arcToAdd): boolean

Add arc to node, given the node interface structure

Parameters

Name Type Description
node DanNode<I, D> the node receiving arcToAdd
arcToAdd DanArc<I, D> -

Returns

boolean

true if arcToAdd was correctly added to the adjacent arcs of node; false if arcToAdd was already present

Defined in

src/undirected_graph/danUndirectedGraph.ts:134


addArcToNodeId

addArcToNodeId(idNode, arcToAdd): boolean

Add an arc to a node, given the node identifier

Parameters

Name Type Description
idNode I the id of the node receiving arcToAdd
arcToAdd DanArc<I, D> the arc being added

Returns

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

Defined in

src/undirected_graph/danUndirectedGraph.ts:98


addNode

addNode(node): boolean

Add a node to the graph

Parameters

Name Type Description
node DanNode<I, D> the node to add

Returns

boolean

true if the node was correctly added to the graph; false if the node is already present

Defined in

src/undirected_graph/danUndirectedGraph.ts:81


countNodes

countNodes(): number

Public method to retrieve the number of nodes in the graph

Returns

number

the number of nodes in the graph

Defined in

src/undirected_graph/danUndirectedGraph.ts:273


getNodeAndUndirectedArcsFromNodeId

getNodeAndUndirectedArcsFromNodeId(idNode): undefined | DanNodeAndUndirectedArcs<I, D>

Get node and undirected arcs structure (as DanNodeAndUndirectedArcs) from nodeId

Parameters

Name Type Description
idNode I the node identifier

Returns

undefined | DanNodeAndUndirectedArcs<I, D>

node and undirected arcs structure or undefined if nodeId is not present in the graph

Defined in

src/undirected_graph/danUndirectedGraph.ts:319


hasNodeId

hasNodeId(idNode): boolean

Check if idNode is present in the graph

Parameters

Name Type Description
idNode I the id of the node

Returns

boolean

true only if idNode is present

Defined in

src/undirected_graph/danUndirectedGraph.ts:328


isAcyclic

isAcyclic(): boolean

Public method to check if the graph is acyclic

Returns

boolean

true if the graph does not contain cycles

Defined in

src/undirected_graph/danUndirectedGraph.ts:253


isConnected

isConnected(): boolean

Check if the graph is connected

Returns

boolean

true if the graph is connected

Defined in

src/undirected_graph/danUndirectedGraph.ts:240


isEmpty

isEmpty(): boolean

Check if the graph is empty

Returns

boolean

true if the graph does not contain any node

Defined in

src/undirected_graph/danUndirectedGraph.ts:281


removeNode

removeNode(idNode): boolean

Remove the node given in input from the graph

Parameters

Name Type Description
idNode I the id of the node to remove

Returns

boolean

true if the node is correctly removed

Defined in

src/undirected_graph/danUndirectedGraph.ts:147


toString

toString(showArcDetails?): string

The string representation of the undirected graph

Parameters

Name Type Default value
showArcDetails boolean false

Returns

string

the string representation of the undirected graph

Defined in

src/undirected_graph/danUndirectedGraph.ts:290


generateConsecutiveNodeGraph

generateConsecutiveNodeGraph(numOfNodes): DanUndirectedGraph<number, undefined>

A utility public static method to generate an undirected graph with a number of numOfNodes consecutive nodes

Parameters

Name Type Description
numOfNodes number the number of nodes of the output graph

Returns

DanUndirectedGraph<number, undefined>

an undirected graph witn numOfNodes nodes

Defined in

src/undirected_graph/danUndirectedGraph.ts:37


generateRandomNodeGraph

generateRandomNodeGraph(numOfNodes): DanUndirectedGraph<number, undefined>

A utility public static method to generate an undirected graph with a number of numOfNodes random nodes

Parameters

Name Type Description
numOfNodes number the number of nodes of the output graph

Returns

DanUndirectedGraph<number, undefined>

an undirected graph witn numOfNodes nodes

Defined in

src/undirected_graph/danUndirectedGraph.ts:59