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

Commit

Permalink
Merge ceb7b4c into 6525b82
Browse files Browse the repository at this point in the history
  • Loading branch information
sbromberger committed Dec 21, 2014
2 parents 6525b82 + ceb7b4c commit 3e6acef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/common.jl
Expand Up @@ -8,8 +8,6 @@ typealias AttributeDict Dict{UTF8String, Any}
#
################################################

vertex_index(v::Integer) = v

immutable KeyVertex{K}
index::Int
key::K
Expand Down
22 changes: 21 additions & 1 deletion src/graph.jl
Expand Up @@ -55,7 +55,16 @@ vertices(g::GenericGraph) = g.vertices
num_edges(g::GenericGraph) = length(g.edges)
edges(g::GenericGraph) = g.edges

vertex_index{V<:ProvidedVertexType}(v::V, g::GenericGraph{V}) = vertex_index(v)
vertex_index(v::Integer, g::SimpleGraph) = (v <= g.vertices[end]? v: 0)

function vertex_index{V<:ProvidedVertexType}(v::V, g::GenericGraph{V})
if applicable(vertex_index, v) # use O(1) if possible
return vertex_index(v)
else # use O(n)
return vertex_index(v,vertices(g))
end
end

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

out_edges{V}(v::V, g::GenericGraph{V}) = g.finclist[vertex_index(v, g)]
Expand All @@ -69,6 +78,17 @@ in_neighbors{V}(v::V, g::GenericGraph{V}) = SourceIterator(g, in_edges(v, g))

# mutation

function add_vertex!(g::SimpleGraph)
# ensure SimpleGraph indices are consecutive, allowing O(1) indexing
v = g.vertices[end] + 1
g.vertices = 1:v
push!(g.finclist, Int[])
push!(g.binclist, Int[])
v
end

@deprecate add_vertex!(g::SimpleGraph,v) add_vertex!(g::SimpleGraph)

function add_vertex!{V}(g::GenericGraph{V}, v::V)
push!(g.vertices, v)
push!(g.finclist, Int[])
Expand Down

0 comments on commit 3e6acef

Please sign in to comment.