Skip to content

Commit

Permalink
refactor: RemoveReferenceVertex removes it's edges automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjarosch committed Mar 5, 2024
1 parent 14beb0a commit c7c2c7c
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions reference/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,27 @@ func AddReferenceVertex(dependencyGraph graph.Graph[string, ValueReference], ref
return nil
}

func RemoveReferenceVertex(dependencyGraph graph.Graph[string, ValueReference], reference ValueReference, dependencies []ValueReference) error {
for _, dependency := range dependencies {
err := dependencyGraph.RemoveEdge(reference.Hash(), dependency.Hash())
if err != nil {
return fmt.Errorf("failed to remove dependency %s: %w", dependency.Name(), err)
func RemoveReferenceVertex(dependencyGraph graph.Graph[string, ValueReference], reference ValueReference) error {
edges, err := dependencyGraph.Edges()
if err != nil {
return err
}

// Find all edges with either originate from or point to the reference and remove them.
for _, edge := range edges {
if edge.Source == reference.Hash() {
err = dependencyGraph.RemoveEdge(edge.Source, edge.Target)
if err != nil {
return err
}
continue
}
if edge.Target == reference.Hash() {
err = dependencyGraph.RemoveEdge(edge.Source, edge.Target)
if err != nil {
return err
}
continue
}
}

Expand Down

0 comments on commit c7c2c7c

Please sign in to comment.