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

OneTo #992

Merged
merged 2 commits into from
Aug 19, 2018
Merged

OneTo #992

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
9 changes: 3 additions & 6 deletions src/SimpleGraphs/SimpleGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function show(io::IO, g::AbstractSimpleGraph{T}) where T
end

nv(g::AbstractSimpleGraph{T}) where T = T(length(fadj(g)))
vertices(g::AbstractSimpleGraph{T}) where T = one(T):nv(g)
vertices(g::AbstractSimpleGraph) = Base.OneTo(nv(g))


edges(g::AbstractSimpleGraph) = SimpleEdgeIter(g)
Expand All @@ -74,11 +74,8 @@ add_edge!(g::AbstractSimpleGraph, x, y) = add_edge!(g, edgetype(g)(x, y))
inneighbors(g::AbstractSimpleGraph, v::Integer) = badj(g, v)
outneighbors(g::AbstractSimpleGraph, v::Integer) = fadj(g, v)

function issubset(g::T, h::T) where T<:AbstractSimpleGraph
(gmin, gmax) = extrema(vertices(g))
(hmin, hmax) = extrema(vertices(h))
return (hmin <= gmin <= gmax <= hmax) && issubset(edges(g), edges(h))
end
issubset(g::T, h::T) where T<:AbstractSimpleGraph =
(nv(g) <= nv(h)) && issubset(edges(g), edges(h))

has_vertex(g::AbstractSimpleGraph, v::Integer) = v in vertices(g)

Expand Down
7 changes: 3 additions & 4 deletions src/centrality/betweenness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function _accumulate_endpoints!(betweenness::Vector{Float64},
δ = zeros(n_v)
σ = state.pathcounts
P = state.predecessors
v1 = [1:n_v;]
v1 = collect(Base.OneTo(n_v))
v2 = state.dists
S = reverse(state.closest_vertices)
s = vertices(g)[si]
Expand Down Expand Up @@ -135,9 +135,8 @@ function _rescale!(betweenness::Vector{Float64}, n::Integer, normalize::Bool, di
if k > 0
scale = scale * n / k
end
for v = 1:length(betweenness)
betweenness[v] *= scale
end
betweenness .*= scale

end
return nothing
end
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Sample `k` element from unit range `r` without repetition and eventually excludi
### Implementation Notes
Unlike [`sample!`](@ref), does not produce side effects.
"""
sample(a::UnitRange, k::Integer; exclude=()) = sample!(getRNG(), collect(a), k; exclude=exclude)
sample(a::AbstractVector, k::Integer; exclude=()) = sample!(getRNG(), collect(a), k; exclude=exclude)

getRNG(seed::Integer=-1) = seed >= 0 ? MersenneTwister(seed) : GLOBAL_RNG

Expand Down