Skip to content

Should undirected edges == and hash be undirected? #184

Open
@DylanModesitt

Description

@DylanModesitt

Edges for SimpleGraph still consider their directedness when testing for equality and hashing. This is understandable given that SimpleEdge is used for directed graphs also. Is it worth considering adding a SimpleUndirectedEdge (or similar)? Something along the lines of:

...

function ==(e1::SimpleUndirectedEdge, e2::SimpleUndirectedEdge)
    return (src(e1) == src(e2) && dst(e1) == dst(e2)) ||
        (src(e1) == dst(e2) && dst(e1) == src(e2))
end

hash(e::SimpleUndirectedEdge, h::UInt) = hash(src(e), h)  hash(dst(e), h)

And then having SimpleGraph instead return edges of this type by default?

This would more easily allow users to maintain sets / dictionaries of edges. For instance, the reason I'm opening this is the associated awkwardness I encountered when implementing a minimum cycle basis that maintains such edge sets.

Happy to do a PR if this change is palatable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions