// weightFuncFor returns a constructed weight function for g. func weightFuncFor(g graph.Undirected) func(x, y graph.Node) float64 { if wg, ok := g.(graph.Weighter); ok { return func(x, y graph.Node) float64 { w, ok := wg.Weight(x, y) if !ok { return 0 } if w < 0 { panic(negativeWeight) } return w } } return func(x, y graph.Node) float64 { e := g.Edge(x, y) if e == nil { return 0 } w := e.Weight() if w < 0 { panic(negativeWeight) } return w } }