(edge: StoredEdge)
| 274 | } |
| 275 | |
| 276 | public addEdge(edge: StoredEdge): void { |
| 277 | if (this.#edges.has(edge.id)) { |
| 278 | throw new Error(`Edge with id ${edge.id} already exists`); |
| 279 | } |
| 280 | this.#edges.set(edge.id, edge); |
| 281 | // inV is the target - it receives incoming edges |
| 282 | const incomingEdges = this.#incomingEdges.get(edge.inV); |
| 283 | if (incomingEdges == null) { |
| 284 | this.#incomingEdges.set(edge.inV, [edge]); |
| 285 | } else { |
| 286 | incomingEdges.push(edge); |
| 287 | } |
| 288 | // outV is the source - it has outgoing edges |
| 289 | const outgoingEdges = this.#outgoingEdges.get(edge.outV); |
| 290 | if (outgoingEdges == null) { |
| 291 | this.#outgoingEdges.set(edge.outV, [edge]); |
| 292 | } else { |
| 293 | outgoingEdges.push(edge); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | public deleteEdge(id: ElementId): void { |
| 298 | const edge = this.#edges.get(id); |
no test coverage detected