Skip to content

Commit

Permalink
Update kruskal.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Aravena authored Feb 6, 2018
1 parent 2d43a60 commit a404514
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/spanningtrees/kruskal.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct KruskalHeapEntry{T<:Real}
edge::AbstractEdge
dist::T
struct KruskalHeapEntry{T<:AbstractEdge, U<:Real}
edge::T
dist::U
end

isless(e1::KruskalHeapEntry, e2::KruskalHeapEntry) = e1.dist < e2.dist
Expand Down Expand Up @@ -29,20 +29,20 @@ distance matrix `distmx` using [Kruskal's algorithm](https://en.wikipedia.org/wi
"""
function kruskal_mst end
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function kruskal_mst{T, U, AG<:AbstractGraph{U}}(
@traitfn function kruskal_mst{T, U, V, AG<:AbstractGraph{U}}(
g::AG::(!IsDirected),
distmx::AbstractMatrix{T} = weights(g)
)

edge_list = Vector{KruskalHeapEntry{T}}()
edge_list = Vector{KruskalHeapEntry{T, U}}()
mst = Vector{AbstractEdge}()
connected_vs = collect(one(U):nv(g))
connected_vs = collect(one(V):nv(g))

sizehint!(edge_list, ne(g))
sizehint!(mst, ne(g))

for e in edges(g)
heappush!(edge_list, KruskalHeapEntry{T}(e, distmx[src(e), dst(e)]))
heappush!(edge_list, KruskalHeapEntry{T, U}(e, distmx[src(e), dst(e)]))
end

while !isempty(edge_list) && length(mst) < nv(g) - 1
Expand Down

0 comments on commit a404514

Please sign in to comment.