Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way of counting edges? #32

Closed
tomjaguarpaw opened this issue May 23, 2016 · 2 comments
Closed

Is there a way of counting edges? #32

tomjaguarpaw opened this issue May 23, 2016 · 2 comments

Comments

@tomjaguarpaw
Copy link
Member

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?

@ivan-m
Copy link
Contributor

ivan-m commented May 23, 2016

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:

  1. 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).
  2. Do you count inverse edges? How about loops?

I may end up adding something along these lines in soon.

@tomjaguarpaw
Copy link
Member Author

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.

@ivan-m ivan-m closed this as completed in 7ce05c4 Jul 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants