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 |
|
|
public |
addVerticies(array: values): Graph |
|
public |
|
|
public |
|
|
public |
getEdgeByValues(start: startValue, end: endValue): Edge |
|
public |
|
|
public |
getEdgesByVertex(vertex: *): Array |
|
public |
getVertexByValue(value: value): Vertex |
|
public |
|
|
public |
getVertices(): Array |
|
public |
hasEdge(start: startVertex, end: endVertex): Boolean |
|
public |
hasVertexWithValue(value: value): Boolean |
Public Constructors
public constructor source
Public Methods
public addEdge(Vertex: startVertex, Vertex: endVertex): Graph source
Params:
Name | Type | Attribute | Description |
Vertex | startVertex | (or value of Vertex) in graph to start |
|
Vertex | endVertex | (or value of Vertex) in graph to end |
Throw:
when adding edge whose value exists in graph. |
public addVertex(value: value): Graph source
Params:
Name | Type | Attribute | Description |
value | value | to set on the vertex |
Throw:
when adding vertex whose value exists in graph. |
public addVerticies(array: values): Graph source
Params:
Name | Type | Attribute | Description |
array | values | of values to add to the 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:
Name | Type | Attribute | Description |
start | startValue | value of edge to locate |
|
end | endValue | value of edge to locate |
public getVertexByValue(value: value): Vertex source
Params:
Name | Type | Attribute | Description |
value | value |
public hasEdge(start: startVertex, end: endVertex): Boolean source
Params:
Name | Type | Attribute | Description |
start | startVertex | value of edge to locate |
|
end | endVertex | value of edge to locate |