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

Improve efficiency of edgeIndices function #1

Open
ianmackenzie opened this issue Aug 19, 2019 · 0 comments
Open

Improve efficiency of edgeIndices function #1

ianmackenzie opened this issue Aug 19, 2019 · 0 comments

Comments

@ianmackenzie
Copy link
Owner

Currently a Set ( Int, Int ) is used to track unique edges, but this involves allocating (and comparing) a lot of tuples. Instead, build up a Set Int where each Int is a packed edge index equal to

lowerVertexIndex * numVertices + higherVertexIndex

Then, once that set is constructed, use Set.foldr to iterate through the set, unpack each Int back into an ( Int, Int ) using mod and //, and accumulate these values into a list. This should maintain the property that edges are returned in sorted order with lower vertex index first and higher vertex index second.

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

1 participant