Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

Int vertex indexing behavior is surprising #127

Closed
Futrell opened this issue Nov 22, 2014 · 0 comments · Fixed by #135
Closed

Int vertex indexing behavior is surprising #127

Futrell opened this issue Nov 22, 2014 · 0 comments · Fixed by #135

Comments

@Futrell
Copy link

Futrell commented Nov 22, 2014

Following up on: https://groups.google.com/forum/#!topic/julia-users/G5zArVhEd3M

This error was very surprising:

julia> using Graphs

julia> g = graph([3, 4], Edge{Int}[])
Directed Graph (2 vertices, 0 edges)

julia> add_edge!(g, 3, 4)
ERROR: BoundsError()
 in add_edge! at /Users/canjo/.julia/v0.4/Graphs/src/graph.jl:86
 in add_edge! at /Users/canjo/.julia/v0.4/Graphs/src/graph.jl:98

julia> edges(g)
1-element Array{Edge{Int64},1}:
 edge [1]: 3 -- 4

From #114 it looks like this is expected behavior because Int indices must be consecutive.
But this was very unexpected to me, because for vertices of other types, I can use arbitrary values:

julia> gs = graph([:cat, :dog], Edge{Symbol}[])
Directed Graph (2 vertices, 0 edges)

julia> add_edge!(gs, :cat, :dog)
edge [1]: cat -- dog

julia> gf = graph([3.0, 4.0], Edge{Float64}[])
Directed Graph (2 vertices, 0 edges)

julia> add_edge!(gf, 3.0, 4.0)
edge [1]: 3.0 -- 4.0

The special behavior of Int vertices seems like it is bound to cause this issue to come up again and again for new users.

Despite throwing the BoundsError, it looks like add_edge! accomplished its work successfully. Can this issue be resolved by something as simple as not throwing the error?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants