MCPcopy Create free account
hub / github.com/driangle/taskmd / calculateDepthMap

Function calculateDepthMap

apps/cli/internal/cli/snapshot_analysis.go:55–94  ·  view source on GitHub ↗

calculateDepthMap calculates dependency depth for each task

(tasks []*model.Task, taskMap map[string]*model.Task)

Source from the content-addressed store, hash-verified

53
54// calculateDepthMap calculates dependency depth for each task
55func calculateDepthMap(tasks []*model.Task, taskMap map[string]*model.Task) map[string]int {
56 memo := make(map[string]int)
57
58 var getDepth func(taskID string, visited map[string]bool) int
59 getDepth = func(taskID string, visited map[string]bool) int {
60 if depth, ok := memo[taskID]; ok {
61 return depth
62 }
63
64 if visited[taskID] {
65 return 0
66 }
67
68 task, exists := taskMap[taskID]
69 if !exists {
70 return 0
71 }
72
73 visited[taskID] = true
74 defer delete(visited, taskID)
75
76 maxDepth := 0
77 for _, depID := range task.Dependencies {
78 depth := getDepth(depID, visited)
79 if depth > maxDepth {
80 maxDepth = depth
81 }
82 }
83
84 result := maxDepth + 1
85 memo[taskID] = result
86 return result
87 }
88
89 for _, task := range tasks {
90 getDepth(task.ID, make(map[string]bool))
91 }
92
93 return memo
94}
95
96// calculateTopologicalOrder assigns a topological order to each task
97func calculateTopologicalOrder(tasks []*model.Task, taskMap map[string]*model.Task) map[string]int {

Callers 6

findCriticalPathTasksFunction · 0.70
runSnapshotFunction · 0.70
TestCalculateDepthMapFunction · 0.70

Calls

no outgoing calls

Tested by 3

TestCalculateDepthMapFunction · 0.56