-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependency_graph.go
More file actions
35 lines (27 loc) · 804 Bytes
/
dependency_graph.go
File metadata and controls
35 lines (27 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package clade
import "github.com/lesomnus/clade/graph"
type DependencyGraph struct {
*graph.Graph[[]*Image]
}
func NewDependencyGraph() *DependencyGraph {
return &DependencyGraph{
Graph: graph.NewGraph[[]*Image](),
}
}
func (g *DependencyGraph) Put(image *Image) *graph.Node[[]*Image] {
node := g.Graph.GetOrPut(image.Name(), []*Image{})
node.Value = append(node.Value, image)
prev_names := make(map[string]bool, 1+len(image.From.Secondaries))
prev_names[image.From.Primary.Name()] = true
for _, base_image := range image.From.Secondaries {
prev_names[base_image.Name()] = true
}
for prev_name := range prev_names {
g.Graph.GetOrPut(prev_name, []*Image{}).
ConnectTo(node)
}
return node
}
func (g *DependencyGraph) Snapshot() graph.Snapshot {
return g.Graph.Snapshot(nil)
}