mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-25 22:46:20 +08:00
Fix JSDoc.
This commit is contained in:
parent
67cdad8030
commit
87ef6e2e48
@ -1,6 +1,6 @@
|
|||||||
export default class Graph {
|
export default class Graph {
|
||||||
/**
|
/**
|
||||||
* @param isDirected {boolean}
|
* @param {boolean} isDirected
|
||||||
*/
|
*/
|
||||||
constructor(isDirected = false) {
|
constructor(isDirected = false) {
|
||||||
this.vertices = {};
|
this.vertices = {};
|
||||||
@ -8,7 +8,7 @@ export default class Graph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param newVertex {GraphVertex}
|
* @param {GraphVertex} newVertex
|
||||||
* @returns {Graph}
|
* @returns {Graph}
|
||||||
*/
|
*/
|
||||||
addVertex(newVertex) {
|
addVertex(newVertex) {
|
||||||
@ -18,7 +18,7 @@ export default class Graph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param vertexKey {string}
|
* @param {string} vertexKey
|
||||||
* @returns GraphVertex
|
* @returns GraphVertex
|
||||||
*/
|
*/
|
||||||
getVertexByKey(vertexKey) {
|
getVertexByKey(vertexKey) {
|
||||||
@ -26,7 +26,7 @@ export default class Graph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param edge {GraphEdge}
|
* @param {GraphEdge} edge
|
||||||
* @returns {Graph}
|
* @returns {Graph}
|
||||||
*/
|
*/
|
||||||
addEdge(edge) {
|
addEdge(edge) {
|
||||||
@ -62,8 +62,8 @@ export default class Graph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param startVertex {GraphVertex}
|
* @param {GraphVertex} startVertex
|
||||||
* @param endVertex {GraphVertex}
|
* @param {GraphVertex} endVertex
|
||||||
*/
|
*/
|
||||||
findEdge(startVertex, endVertex) {
|
findEdge(startVertex, endVertex) {
|
||||||
const vertex = this.getVertexByKey(startVertex.getKey());
|
const vertex = this.getVertexByKey(startVertex.getKey());
|
||||||
@ -71,7 +71,7 @@ export default class Graph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param vertexKey {string}
|
* @param {string} vertexKey
|
||||||
* @returns {GraphVertex}
|
* @returns {GraphVertex}
|
||||||
*/
|
*/
|
||||||
findVertexByKey(vertexKey) {
|
findVertexByKey(vertexKey) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
export default class GraphEdge {
|
export default class GraphEdge {
|
||||||
/**
|
/**
|
||||||
* @param startVertex {GraphVertex}
|
* @param {GraphVertex} startVertex
|
||||||
* @param endVertex {GraphVertex}
|
* @param {GraphVertex} endVertex
|
||||||
* @param weight {number}
|
* @param {number} [weight=1]
|
||||||
*/
|
*/
|
||||||
constructor(startVertex, endVertex, weight = 1) {
|
constructor(startVertex, endVertex, weight = 1) {
|
||||||
this.startVertex = startVertex;
|
this.startVertex = startVertex;
|
||||||
|
@ -13,7 +13,7 @@ export default class GraphVertex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param edge {GraphEdge}
|
* @param {GraphEdge} edge
|
||||||
* @returns {GraphVertex}
|
* @returns {GraphVertex}
|
||||||
*/
|
*/
|
||||||
addEdge(edge) {
|
addEdge(edge) {
|
||||||
@ -22,6 +22,9 @@ export default class GraphVertex {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {GraphVertex[]}
|
||||||
|
*/
|
||||||
getNeighbors() {
|
getNeighbors() {
|
||||||
const edges = this.edges.toArray();
|
const edges = this.edges.toArray();
|
||||||
|
|
||||||
@ -35,7 +38,7 @@ export default class GraphVertex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param requiredEdge {GraphEdge}
|
* @param {GraphEdge} requiredEdge
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
hasEdge(requiredEdge) {
|
hasEdge(requiredEdge) {
|
||||||
@ -47,7 +50,7 @@ export default class GraphVertex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param vertex {GraphVertex}
|
* @param {GraphVertex} vertex
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
hasNeighbor(vertex) {
|
hasNeighbor(vertex) {
|
||||||
@ -58,6 +61,10 @@ export default class GraphVertex {
|
|||||||
return !!vertexNode;
|
return !!vertexNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {GraphVertex} vertex
|
||||||
|
* @returns {(GraphEdge|null)}
|
||||||
|
*/
|
||||||
findEdge(vertex) {
|
findEdge(vertex) {
|
||||||
const edgeFinder = (edge) => {
|
const edgeFinder = (edge) => {
|
||||||
return edge.startVertex === vertex || edge.endVertex === vertex;
|
return edge.startVertex === vertex || edge.endVertex === vertex;
|
||||||
@ -76,7 +83,7 @@ export default class GraphVertex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param callback {function}
|
* @param {function} [callback]
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
toString(callback) {
|
toString(callback) {
|
||||||
|
Loading…
Reference in New Issue
Block a user