aysylu / loom

Graph library for Clojure. Mailing list https://groups.google.com/forum/#!forum/loom-clj
http://aysy.lu/loom/
886 stars 108 forks source link

Bug in implementation of weight #141

Open Engelberg opened 3 months ago

Engelberg commented 3 months ago

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)))