graph

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GraphEngine

type GraphEngine struct {
	// contains filtered or unexported fields
}

GraphEngine maintains an in-memory directed graph of code relationships

func New

func New() *GraphEngine

New creates a new GraphEngine

func (*GraphEngine) AddEdge

func (g *GraphEngine) AddEdge(edge types.ASTEdge)

AddEdge adds a single edge to the graph

func (*GraphEngine) BlastRadius

func (g *GraphEngine) BlastRadius(nodeHashID string, maxDepth int) []string

BlastRadius performs BFS over incoming edges to find all nodes that depend on (directly or transitively call) the given node, up to maxDepth hops away. Edges represent "A calls B" (source=caller, target=callee), so to find who calls A we must traverse in reverse — following edges that point TO each node. g.dg.To(nodeID) returns the predecessors of nodeID (nodes with edges into it).

func (*GraphEngine) BlastRadiusWithDepth

func (g *GraphEngine) BlastRadiusWithDepth(nodeHashID string, maxDepth int) map[string]int

BlastRadiusWithDepth performs BFS over incoming edges (same as BlastRadius) but returns a map of hash ID → hop depth instead of a flat list.

func (*GraphEngine) BuildFromEdges

func (g *GraphEngine) BuildFromEdges(edges []types.ASTEdge, validNodeIDs ...map[string]bool)

BuildFromEdges reconstructs the entire graph from a slice of edges. If validNodeIDs is non-nil, edges referencing unknown nodes are skipped to prevent ghost nodes from orphaned database rows.

func (*GraphEngine) ChangeCount

func (g *GraphEngine) ChangeCount() int

ChangeCount returns the number of incremental graph mutations since last reset. Used to decide when to trigger async betweenness recomputation.

func (*GraphEngine) CollectDeps

func (g *GraphEngine) CollectDeps(hashID string, depth int) (deps []string, dependents []string)

CollectDeps collects callees (outgoing) and callers (incoming) up to a given depth from a starting node. Returns two sets: dependencies (callees) and dependents (callers).

func (*GraphEngine) ComputeBetweenness

func (g *GraphEngine) ComputeBetweenness() map[string]float64

ComputeBetweenness computes betweenness centrality for all nodes using Brandes' algorithm (via gonum), normalized to [0,1] using the graph-theoretic maximum for directed graphs: (n-1)*(n-2), where n = number of nodes. This makes scores comparable across different graph states.

func (*GraphEngine) ComputeInDegree

func (g *GraphEngine) ComputeInDegree() map[string]float64

ComputeInDegree computes the in-degree authority for all nodes, normalized to [0,1]. In-degree counts how many other nodes have edges pointing TO each node. Results are cached and invalidated on graph mutations.

func (*GraphEngine) ComputeSearchSignals

func (g *GraphEngine) ComputeSearchSignals(activeNodeIDs []string) (ppr map[string]float64, inDegree map[string]float64)

ComputeSearchSignals computes PPR and InDegree for search. Takes a brief read lock to snapshot graph data and in-degree cache, then releases the lock before running the iterative PPR computation. This avoids serializing concurrent searches.

func (*GraphEngine) ComputeSearchSignalsSubgraph

func (g *GraphEngine) ComputeSearchSignalsSubgraph(seedIDs, candidateIDs []string) (ppr map[string]float64, inDegree map[string]float64)

ComputeSearchSignalsSubgraph computes PPR on the candidate subgraph and returns InDegree from cache. Takes a brief read lock to snapshot the subgraph data and in-degree cache, then releases the lock before running PPR computation. This avoids holding any lock during the iterative PPR walk, which would serialize all concurrent searches unnecessarily.

func (*GraphEngine) DetectCommunities

func (g *GraphEngine) DetectCommunities() ([]types.Community, float64)

DetectCommunities uses Louvain community detection to find tightly coupled clusters of code symbols. Results are cached and invalidated on graph rebuild.

func (*GraphEngine) EdgeCount

func (g *GraphEngine) EdgeCount() int

EdgeCount returns the number of edges in the graph

func (*GraphEngine) GetCallees

func (g *GraphEngine) GetCallees(hashID string) []string

GetCallees returns the hash IDs of all nodes that the given node calls (outgoing edges).

func (*GraphEngine) GetCallers

func (g *GraphEngine) GetCallers(hashID string) []string

GetCallers returns the hash IDs of all nodes that call the given node (incoming edges).

func (*GraphEngine) GetConnectors

func (g *GraphEngine) GetConnectors(betweenness map[string]float64, limit int) []string

GetConnectors returns nodes that bridge communities — they have high betweenness and edges to nodes in multiple communities. Returns hash IDs. Uses a single write lock to prevent race conditions where BuildFromEdges could replace the graph between community detection check and the read of graph data.

func (*GraphEngine) GetEntryPoints

func (g *GraphEngine) GetEntryPoints() []string

GetEntryPoints returns nodes with zero in-degree (nobody calls them; they initiate).

func (*GraphEngine) GetHubs

func (g *GraphEngine) GetHubs(limit int) []struct {
	HashID    string
	OutDegree int
}

GetHubs returns nodes with the highest out-degree (they call many things). Returns up to limit nodes sorted by out-degree descending.

func (*GraphEngine) GetInDegree

func (g *GraphEngine) GetInDegree(hashID string) int

GetInDegree returns the in-degree (number of incoming edges) for a node.

func (*GraphEngine) GetOutDegree

func (g *GraphEngine) GetOutDegree(hashID string) int

GetOutDegree returns the out-degree (number of outgoing edges) for a node.

func (*GraphEngine) HasNode

func (g *GraphEngine) HasNode(hashID string) bool

HasNode checks if a node exists in the graph

func (*GraphEngine) NodeCount

func (g *GraphEngine) NodeCount() int

NodeCount returns the number of nodes in the graph

func (*GraphEngine) PageRank

func (g *GraphEngine) PageRank() map[string]float64

PageRank computes standard (non-personalized) PageRank and returns a map of hash ID to score.

func (*GraphEngine) PersonalizedPageRank

func (g *GraphEngine) PersonalizedPageRank(activeNodeIDs []string) map[string]float64

PersonalizedPageRank implements true Personalized PageRank via custom power iteration. The teleportation vector is seeded with the active nodes instead of uniform distribution, so random walks that "restart" teleport back to the active context rather than random nodes. activeNodeIDs are the hash IDs of nodes in the currently edited files / top FTS results.

func (*GraphEngine) PersonalizedPageRankSubgraph

func (g *GraphEngine) PersonalizedPageRankSubgraph(seedIDs, candidateIDs []string) map[string]float64

PersonalizedPageRankSubgraph runs PPR on a subgraph induced by candidateIDs. Only candidate nodes participate in the random walk, dramatically reducing computation for large graphs (12K nodes → ~100 candidate nodes).

func (*GraphEngine) RemoveEdge

func (g *GraphEngine) RemoveEdge(sourceHash, targetHash string)

RemoveEdge removes a single edge from the graph

func (*GraphEngine) RemoveNode

func (g *GraphEngine) RemoveNode(hashID string)

RemoveNode removes a node and all its edges from the graph

func (*GraphEngine) ResetChangeCount

func (g *GraphEngine) ResetChangeCount()

ResetChangeCount resets the incremental change counter to zero.

func (*GraphEngine) TraceCallPath

func (g *GraphEngine) TraceCallPath(fromHash, toHash string, maxDepth int) [][]string

TraceCallPath performs bidirectional BFS to find call paths between two symbols. It searches forward from the source (outgoing edges) and backward from the target (incoming edges) until the frontiers meet, then reconstructs all found paths. Returns a list of paths (each path is a list of hash IDs) up to maxDepth total hops.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL