Home Reference Source
public class | source

Graph

Graph: represents a undirected graph data structure. Usage: let graph = new Graph(); graph.addVertex('A'); graph.addVertex('B'); graph.addEdge('A','B');

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

addEdge(Vertex: startVertex, Vertex: endVertex): Graph

public

addVertex(value: value): Graph

public

addVerticies(array: values): Graph

public
public
public

getEdgeByValues(start: startValue, end: endValue): Edge

public
public

getEdgesByVertex(vertex: *): Array

public
public
public
public
public

Public Constructors

public constructor source

Public Methods

public addEdge(Vertex: startVertex, Vertex: endVertex): Graph source

Params:

NameTypeAttributeDescription
Vertex startVertex

(or value of Vertex) in graph to start

Vertex endVertex

(or value of Vertex) in graph to end

Return:

Graph

current instance of graph.

Throw:

DuplicateEdgeError

when adding edge whose value exists in graph.

public addVertex(value: value): Graph source

Params:

NameTypeAttributeDescription
value value

to set on the vertex

Return:

Graph

current instance of graph.

Throw:

DuplicateVertexError

when adding vertex whose value exists in graph.

public addVerticies(array: values): Graph source

Params:

NameTypeAttributeDescription
array values

of values to add to the graph

Return:

Graph

current instance of graph.

public getAdjacencyList(): Object source

Return:

Object

each Object key represents a vertex in graph; value at each key is an array of vertex values found in edge destinations.

public getAdjacencyMatrix(): Array source

Return:

Array

array of arrays; each entry represents adjacency for row; each entry in each sub-array represents adjacency for column; if A[i][j] = 1, there is an edge from i to j.

public getEdgeByValues(start: startValue, end: endValue): Edge source

Params:

NameTypeAttributeDescription
start startValue

value of edge to locate

end endValue

value of edge to locate

Return:

Edge

returns Edge instance in Graph if exists, otherwise returns undefined

public getEdges(): Array source

Return:

Array

array of Edge instances present in Graph.

public getEdgesByVertex(vertex: *): Array source

Params:

NameTypeAttributeDescription
vertex *

Return:

Array

given Vertex A, return all values from vertices connected to A by edges.

public getVertexByValue(value: value): Vertex source

Params:

NameTypeAttributeDescription
value value

Return:

Vertex

instance of Vertex in graph with value, else undefined

public getVertexValues(): Array source

Return:

Array

array of values in all graph vertices.

public getVertices(): Array source

Return:

Array

array of all Vertex instances in this graph.

public hasEdge(start: startVertex, end: endVertex): Boolean source

Params:

NameTypeAttributeDescription
start startVertex

value of edge to locate

end endVertex

value of edge to locate

Return:

Boolean

true if any edge has these start and end values else false

public hasVertexWithValue(value: value): Boolean source

Params:

NameTypeAttributeDescription
value value

to find in the graph.

Return:

Boolean

true if any vertex has this value else false