MCPcopy Index your code
hub / github.com/trekhleb/javascript-algorithms / addVertex

Method addVertex

src/data-structures/graph/Graph.js:15–25  ·  view source on GitHub ↗

* @param {GraphVertex} newVertex * @returns {Graph}

(newVertex)

Source from the content-addressed store, hash-verified

13 * @returns {Graph}
14 */
15 addVertex(newVertex) {
16 const key = newVertex.getKey();
17
18 if (this.vertices[key]) {
19 throw new Error('Vertex has already been added before');
20 }
21
22 this.vertices[key] = newVertex;
23
24 return this;
25 }
26
27 /**
28 * @param {string} vertexKey

Callers 6

addEdgeMethod · 0.95
addSameEdgeTwiceFunction · 0.95
Graph.test.jsFile · 0.80
dijkstra.test.jsFile · 0.80

Calls 1

getKeyMethod · 0.45

Tested by 1

addSameEdgeTwiceFunction · 0.76