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

Method deleteVertex

packages/graph/src/GraphStorage.ts:234–274  ·  view source on GitHub ↗
(id: ElementId)

Source from the content-addressed store, hash-verified

232 }
233
234 public deleteVertex(id: ElementId): void {
235 const vertex = this.#vertices.get(id);
236 if (vertex == null) {
237 throw new VertexNotFoundError(id);
238 }
239 // For incoming edges, this vertex is the target (inV)
240 // We need to remove the edge from the source's outgoing edges
241 const incomingEdges = this.#incomingEdges.get(id);
242 if (incomingEdges != null) {
243 for (const edge of incomingEdges) {
244 // edge.outV is the source - remove from its outgoing edges
245 const outgoingEdges = this.#outgoingEdges.get(edge.outV);
246 if (outgoingEdges != null) {
247 const index = outgoingEdges.indexOf(edge);
248 if (index !== -1) {
249 outgoingEdges.splice(index, 1);
250 }
251 }
252 this.#edges.delete(edge.id);
253 }
254 this.#incomingEdges.delete(id);
255 }
256 // For outgoing edges, this vertex is the source (outV)
257 // We need to remove the edge from the target's incoming edges
258 const outgoingEdges = this.#outgoingEdges.get(id);
259 if (outgoingEdges != null) {
260 for (const edge of outgoingEdges) {
261 // edge.inV is the target - remove from its incoming edges
262 const incomingEdges = this.#incomingEdges.get(edge.inV);
263 if (incomingEdges != null) {
264 const index = incomingEdges.indexOf(edge);
265 if (index !== -1) {
266 incomingEdges.splice(index, 1);
267 }
268 }
269 this.#edges.delete(edge.id);
270 }
271 this.#outgoingEdges.delete(id);
272 }
273 this.#vertices.delete(id);
274 }
275
276 public addEdge(edge: StoredEdge): void {
277 if (this.#edges.has(edge.id)) {

Callers

nothing calls this directly

Calls 1

getMethod · 0.65

Tested by

no test coverage detected