MCPcopy Create free account
hub / github.com/codemix/graph / addEdge

Method addEdge

packages/graph/src/GraphStorage.ts:276–295  ·  view source on GitHub ↗
(edge: StoredEdge)

Source from the content-addressed store, hash-verified

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);

Callers 1

constructorMethod · 0.95

Calls 3

getMethod · 0.65
hasMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected