The weight function is supposed to dispatch to the weight* protocol. The weight* protocol has implementors implement an arity for discovering the weight of an edge: (weight* g e). However, the weight function completely ignores this aspect of the protocol and never calls it for edges. The existing implementation of weight calls weight* instead on the src and dest nodes, which poses a problem for graphs where the edge is not uniquely determined by src and dest.
The correct implementation of weight which respects the full weight* protocol is:
(defn weight
"Returns the weight of edge e or edge [n1 n2]"
([g] (partial weight g))
([g e] (weight* g e))
([g n1 n2] (weight* g n1 n2)))
The
weight
function is supposed to dispatch to theweight*
protocol. Theweight*
protocol has implementors implement an arity for discovering the weight of an edge:(weight* g e)
. However, theweight
function completely ignores this aspect of the protocol and never calls it for edges. The existing implementation ofweight
callsweight*
instead on the src and dest nodes, which poses a problem for graphs where the edge is not uniquely determined by src and dest.The correct implementation of weight which respects the full weight* protocol is: