perf:make findFeasiblePaths faster

Signed-off-by: qinguoyi <1532979219@qq.com>
This commit is contained in:
qinguoyi 2024-08-07 09:44:35 +08:00
parent b4b6d692ca
commit a98041281d
1 changed files with 17 additions and 0 deletions

View File

@ -158,6 +158,23 @@ func findFeasiblePaths(groups []*GroupInfo, minConstraint, maxConstraint, target
})
}
if len(groups) < minConstraint {
return
}
if len(groups) == minConstraint {
var sum int
rootPath := new(dfsPath)
for _, i := range groups {
sum += i.value
rootPath.enqueue(i)
}
if sum >= target {
paths = append(paths, rootPath.next())
}
return
}
rootPath := new(dfsPath)
var dfsFunc func(int, int)
dfsFunc = func(sum, begin int) {