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

Function NewGraph

sdk/go/graph/graph.go:65–90  ·  view source on GitHub ↗

NewGraph creates a new graph from a list of tasks

(tasks []*model.Task)

Source from the content-addressed store, hash-verified

63
64// NewGraph creates a new graph from a list of tasks
65func NewGraph(tasks []*model.Task) *Graph {
66 g := &Graph{
67 Tasks: tasks,
68 TaskMap: make(map[string]*model.Task),
69 Adjacency: make(map[string][]string),
70 RevAdjacency: make(map[string][]string),
71 }
72
73 // Build task map
74 for _, task := range tasks {
75 g.TaskMap[task.ID] = task
76 }
77
78 // Build adjacency lists
79 for _, task := range tasks {
80 for _, depID := range task.Dependencies {
81 // task depends on depID
82 // so depID -> task in forward adjacency (depID blocks task)
83 g.Adjacency[depID] = append(g.Adjacency[depID], task.ID)
84 // task -> depID in reverse adjacency
85 g.RevAdjacency[task.ID] = append(g.RevAdjacency[task.ID], depID)
86 }
87 }
88
89 return g
90}
91
92// GetDownstream returns all tasks that depend on the given task (transitively)
93func (g *Graph) GetDownstream(taskID string) map[string]bool {

Callers 15

TestNewGraphFunction · 0.85
TestGetDownstreamFunction · 0.85
TestGetUpstreamFunction · 0.85
TestDetectCyclesFunction · 0.85
TestDetectNoCyclesFunction · 0.85
TestFilterTasksFunction · 0.85
TestToMermaidFunction · 0.85
TestToDotFunction · 0.85
TestToASCIIFunction · 0.85
TestToJSONFunction · 0.85

Calls

no outgoing calls

Tested by 14

TestNewGraphFunction · 0.68
TestGetDownstreamFunction · 0.68
TestGetUpstreamFunction · 0.68
TestDetectCyclesFunction · 0.68
TestDetectNoCyclesFunction · 0.68
TestFilterTasksFunction · 0.68
TestToMermaidFunction · 0.68
TestToDotFunction · 0.68
TestToASCIIFunction · 0.68
TestToJSONFunction · 0.68