You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there really no way of counting edges in a graph? Graph has the noNodes method but there seems to be nothing corresponding to the number of edges. I hacked together this
noEdges :: FGL.Graph gr => gr a b -> Int
noEdges = FGL.ufold (\(a, _, _, a') i -> i + length a + length a') 0
but surely this functionality should be exposed from the library?
The text was updated successfully, but these errors were encountered:
Well, my go-to solution would have been length . labEdges or something along those lines. Especially as your solution might double-count loops (I don't recall off the top of my head how ufold handles loops).
I suspect the reason there currently isn't such a function (which should really be called size) whereas labNodes (the proper name of which is order) is two-fold:
noNodes is easily defined - and more efficiently so - using the underlying implementation, especially the Map-based Tree implementation (I think this is the one way that Tree outperforms PatriciaTree).
Do you count inverse edges? How about loops?
I may end up adding something along these lines in soon.
You're right, length . labEdges is much better. But my confusion on this is strong evidence that there really needs to be a single function which does this.
Is there really no way of counting edges in a graph?
Graph
has thenoNodes
method but there seems to be nothing corresponding to the number of edges. I hacked together thisbut surely this functionality should be exposed from the library?
The text was updated successfully, but these errors were encountered: