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.
Currently a
Set ( Int, Int )is used to track unique edges, but this involves allocating (and comparing) a lot of tuples. Instead, build up aSet Intwhere eachIntis a packed edge index equal toThen, once that set is constructed, use
Set.foldrto iterate through the set, unpack eachIntback into an( Int, Int )usingmodand//, 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.