Neighbors returns the adjacent nodes ordered by edge weight (desc), then ID (asc) for stability.
(id string)
| 160 | // Neighbors returns the adjacent nodes ordered by edge weight (desc), then ID |
| 161 | // (asc) for stability. |
| 162 | func (g *Graph) Neighbors(id string) []Neighbor { |
| 163 | adj := g.adj[id] |
| 164 | out := make([]Neighbor, 0, len(adj)) |
| 165 | for nid, w := range adj { |
| 166 | out = append(out, Neighbor{ID: nid, Weight: w}) |
| 167 | } |
| 168 | sort.Slice(out, func(i, j int) bool { |
| 169 | if out[i].Weight != out[j].Weight { |
| 170 | return out[i].Weight > out[j].Weight |
| 171 | } |
| 172 | return out[i].ID < out[j].ID |
| 173 | }) |
| 174 | return out |
| 175 | } |
| 176 | |
| 177 | // Hubs returns the most connected nodes (weighted degree, then intrinsic |
| 178 | // weight, then ID), capped at limit. Hubs are the backbone of the index card. |
no outgoing calls