mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Make it possible to delete edge from graph vertex.
This commit is contained in:
@@ -9,10 +9,22 @@ export default class GraphVertex {
|
||||
throw new Error('Graph vertex must have a value');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {GraphEdge} edgeA
|
||||
* @param {GraphEdge} edgeB
|
||||
*/
|
||||
const edgeComparator = (edgeA, edgeB) => {
|
||||
if (edgeA.getKey() === edgeB.getKey()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return edgeA.getKey() < edgeB.getKey() ? -1 : 1;
|
||||
};
|
||||
|
||||
// Normally you would store string value like vertex name.
|
||||
// But generally it may be any object as well
|
||||
this.value = value;
|
||||
this.edges = new LinkedList();
|
||||
this.edges = new LinkedList(edgeComparator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,6 +37,13 @@ export default class GraphVertex {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {GraphEdge} edge
|
||||
*/
|
||||
deleteEdge(edge) {
|
||||
this.edges.delete(edge);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {GraphVertex[]}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user