Documentation
¶
Overview ¶
Package dependency constructs the project dependency DAG, translating path strings to node IDs.
Index ¶
- Variables
- func Build(w *types.Workspace, opts ...types.GraphOption) (*types.Graph, error)
- type AffectedPath
- type BuildOption
- type BuildStats
- type Builder
- type Graph
- func (g *Graph) BlastRadius() []int32
- func (g *Graph) ID(path string) (ID, bool)
- func (g *Graph) Len() int
- func (g *Graph) NCCD() float64
- func (g *Graph) NearCycles(ctx context.Context, maxDepth int) []NearCycle
- func (g *Graph) Nodes() iter.Seq[ID]
- func (g *Graph) Path(id ID) (string, bool)
- func (g *Graph) PathsFromSeeds(target ID, seeds []ID, out []AffectedPath) []AffectedPath
- func (g *Graph) Predecessors(id ID) iter.Seq[ID]
- func (g *Graph) Reachable(u, v ID) bool
- func (g *Graph) ReverseClosure(dst []ID, seeds []ID) []ID
- func (g *Graph) Successors(id ID) iter.Seq[ID]
- func (g *Graph) TopoOrder() []ID
- type ID
- type NearCycle
- type NoopObserver
- type Observer
- type QueryEvent
Constants ¶
This section is empty.
Variables ¶
var ErrCycle = errors.New("graph: dependency cycle")
ErrCycle is returned by Builder.Build when the edge set forms a cycle.
Functions ¶
Types ¶
type AffectedPath ¶
AffectedPath is one chain from a seed node to a target node, in seed-first order.
type BuildOption ¶
type BuildOption func(*buildCfg)
BuildOption configures a Build call.
func WithObserver ¶
func WithObserver(o Observer) BuildOption
WithObserver attaches obs to the resulting Graph (query → OnQuery; build → OnBuild).
type BuildStats ¶
BuildStats is emitted once per successful Builder.Build.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder accumulates nodes and edges; not safe for concurrent use.
func (*Builder) AddEdge ¶
AddEdge records a directed edge from→to (silently deduplicates); cycle detection is in Build.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is an immutable DAG; all methods are safe for concurrent use.
func (*Graph) BlastRadius ¶
BlastRadius returns, for each node, the count of nodes that can transitively reach it.
func (*Graph) NearCycles ¶
NearCycles returns pairs where adding From→To would close a cycle of length ≤ maxDepth.
func (*Graph) PathsFromSeeds ¶
func (g *Graph) PathsFromSeeds(target ID, seeds []ID, out []AffectedPath) []AffectedPath
PathsFromSeeds returns the shortest seed→target chain for each reachable seed, sorted by seed ID.
func (*Graph) Predecessors ¶
Predecessors iterates over direct dependents of id.
func (*Graph) ReverseClosure ¶
ReverseClosure returns every node that can reach any seed, sorted by ID. Uses BFS for small graphs and the bitset closure for large ones.
func (*Graph) Successors ¶
Successors iterates over direct dependencies of id.
type ID ¶
type ID int32
ID identifies a node; stable for the lifetime of a Graph, assigned in lexicographic order. Do not use a Builder ID to index a Graph (reassigned at Build).
const NoID ID = -1
NoID is the zero value returned when a lookup fails.
type NearCycle ¶
NearCycle describes an ordered pair where adding the edge From→To would create a cycle of length ≤ maxDepth.
type NoopObserver ¶
type NoopObserver struct{}
NoopObserver discards every event.
func (NoopObserver) OnBuild ¶
func (NoopObserver) OnBuild(BuildStats)
func (NoopObserver) OnError ¶
func (NoopObserver) OnError(error)
func (NoopObserver) OnQuery ¶
func (NoopObserver) OnQuery(QueryEvent)
type Observer ¶
type Observer interface {
OnBuild(BuildStats)
OnQuery(QueryEvent)
OnError(error)
}
Observer receives structured events from a Graph; implementations must be concurrency-safe.
type QueryEvent ¶
type QueryEvent struct {
Op string // method name
Nodes int // |V|
Seeds int // seed-set size, or 0 when N/A
Strategy string // "bfs" or "bitset"
ResultCount int // closure size, path count, or pair count
Duration time.Duration
}
QueryEvent is emitted once per top-level query method.