MCPcopy Create free account
hub / github.com/diillson/chatcli / AddEdge

Method AddEdge

pkg/knowledge/graph.go:96–117  ·  view source on GitHub ↗

AddEdge adds (or reinforces) an undirected edge. It is a no-op when either endpoint is missing or when a == b, so callers can wire edges optimistically without pre-checking existence. Repeated edges accumulate weight.

(a, b string, w float64)

Source from the content-addressed store, hash-verified

94// endpoint is missing or when a == b, so callers can wire edges optimistically
95// without pre-checking existence. Repeated edges accumulate weight.
96func (g *Graph) AddEdge(a, b string, w float64) {
97 if a == b {
98 return
99 }
100 if _, ok := g.nodes[a]; !ok {
101 return
102 }
103 if _, ok := g.nodes[b]; !ok {
104 return
105 }
106 if w <= 0 {
107 w = 1
108 }
109 if g.adj[a] == nil {
110 g.adj[a] = make(map[string]float64)
111 }
112 if g.adj[b] == nil {
113 g.adj[b] = make(map[string]float64)
114 }
115 g.adj[a][b] += w
116 g.adj[b][a] += w
117}
118
119// Node returns a node by ID.
120func (g *Graph) Node(id string) (*Node, bool) {

Callers 6

sampleGraphFunction · 0.80
dotSampleGraphFunction · 0.80
addMemoryNodesMethod · 0.80
addSkillNodesMethod · 0.80
linkWikilinksFunction · 0.80

Calls

no outgoing calls

Tested by 3

sampleGraphFunction · 0.64
dotSampleGraphFunction · 0.64