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

Fix issue in vertex_index #182

Merged
merged 3 commits into from
Jun 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ vertex_index(v::Integer, g::SimpleGraph) = (v <= g.vertices[end]? v: 0)
# If V is either ExVertex or KeyVertex call vertex_index on v
vertex_index{V<:ProvidedVertexType}(v::V, g::GenericGraph{V}) = vertex_index(v)
# Else return index given by dictionary
vertex_index{V}(v::V,g::GenericGraph{V}) = try g.indexof[v] catch 0 end
vertex_index{V<:ProvidedVertexType}(v::V,g::GenericGraph{V}) = try g.indexof[v] catch 0 end

edge_index{V,E}(e::E, g::GenericGraph{V,E}) = edge_index(e)

Expand Down
22 changes: 20 additions & 2 deletions test/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,23 @@ g = graph(v,e,is_directed=true)
# Integer vertices and edges
n = 100
m = 1000
vs = rand(1:10*n,n)

# We ensure that vertices have random but different values
function uniqueRands(range,nb::Int)
result=Dict{Int,Bool}()
i= 0
while i < nb
r = rand(1:10*n)
if !haskey( result, r)
i += 1
result[r] = true
end
end
collect(keys(result))
end

vs = uniqueRands(1:10*n,n)

es = Edge{Int}[]
for i in 1:m
push!(es,Edge(i,vs[rand(1:n)],vs[rand(1:n)]))
Expand All @@ -298,7 +314,9 @@ end
# same for undirected graph
n = 100
m = 1000
vs = rand(1:10*n,n)

vs = uniqueRands(1:10*n,n)

es = Edge{Int}[]
for i in 1:m
push!(es,Edge(i,vs[rand(1:n)],vs[rand(1:n)]))
Expand Down