From 7e8514b4b2b1b8fdd13b34f81d60acef84dfd227 Mon Sep 17 00:00:00 2001 From: ddddddO Date: Mon, 4 Nov 2024 16:08:51 +0900 Subject: [PATCH] split file --- critical_path.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ plantuml.go | 62 ----------------------------------------------- 2 files changed, 63 insertions(+), 62 deletions(-) create mode 100644 critical_path.go diff --git a/critical_path.go b/critical_path.go new file mode 100644 index 0000000..33dcc9e --- /dev/null +++ b/critical_path.go @@ -0,0 +1,63 @@ +package gdag + +type criticalPath struct { + path map[int]struct{} // key は Node の index + sumHour float64 +} + +func (cp *criticalPath) contains(n *Node) bool { + _, ok := cp.path[n.index] + return ok +} + +type criticalPathCalculator struct { + allPaths [][]*Node // start からすべてのパス +} + +func newCriticalPathCalculator() *criticalPathCalculator { + return &criticalPathCalculator{} +} + +func (cc *criticalPathCalculator) getCriticalPaths(start *Node) []*criticalPath { + cc.walk(start, []*Node{}) + + criticalPaths := []*criticalPath{} + for _, path := range cc.allPaths { + critical := &criticalPath{path: map[int]struct{}{}} + for _, n := range path { + critical.path[n.index] = struct{}{} + critical.sumHour += n.hour + } + + if critical.sumHour == 0 { + continue + } + if len(criticalPaths) == 0 { + criticalPaths = append(criticalPaths, critical) + continue + } + if critical.sumHour == criticalPaths[0].sumHour { + criticalPaths = append(criticalPaths, critical) + continue + } + if critical.sumHour > criticalPaths[0].sumHour { + criticalPaths = []*criticalPath{critical} + continue + } + } + + return criticalPaths +} + +func (cc *criticalPathCalculator) walk(current *Node, path []*Node) { + path = append(path, current) + + if len(current.downstream) == 0 { + cc.allPaths = append(cc.allPaths, path) + return + } + + for _, n := range current.downstream { + cc.walk(n, path) + } +} diff --git a/plantuml.go b/plantuml.go index f551f72..b44206b 100644 --- a/plantuml.go +++ b/plantuml.go @@ -33,68 +33,6 @@ func (start *Node) UMLNoCritical() (string, error) { return ret, nil } -type criticalPath struct { - path map[int]struct{} // key は Node の index - sumHour float64 -} - -func (cp *criticalPath) contains(n *Node) bool { - _, ok := cp.path[n.index] - return ok -} - -type criticalPathCalculator struct { - allPaths [][]*Node // start からすべてのパス -} - -func newCriticalPathCalculator() *criticalPathCalculator { - return &criticalPathCalculator{} -} - -func (cc *criticalPathCalculator) getCriticalPaths(start *Node) []*criticalPath { - cc.walk(start, []*Node{}) - - criticalPaths := []*criticalPath{} - for _, path := range cc.allPaths { - critical := &criticalPath{path: map[int]struct{}{}} - for _, n := range path { - critical.path[n.index] = struct{}{} - critical.sumHour += n.hour - } - - if critical.sumHour == 0 { - continue - } - if len(criticalPaths) == 0 { - criticalPaths = append(criticalPaths, critical) - continue - } - if critical.sumHour == criticalPaths[0].sumHour { - criticalPaths = append(criticalPaths, critical) - continue - } - if critical.sumHour > criticalPaths[0].sumHour { - criticalPaths = []*criticalPath{critical} - continue - } - } - - return criticalPaths -} - -func (cc *criticalPathCalculator) walk(current *Node, path []*Node) { - path = append(path, current) - - if len(current.downstream) == 0 { - cc.allPaths = append(cc.allPaths, path) - return - } - - for _, n := range current.downstream { - cc.walk(n, path) - } -} - type umlGenerator struct { criticalPaths []*criticalPath uniqueComponents map[int]struct{}