@@ -302,11 +302,7 @@ function acyclic_coloring(g::AdjacencyGraph, order::AbstractOrder; postprocessin
302302 forbidden_colors = zeros (Int, nv)
303303 first_neighbor = fill ((0 , 0 ), nv) # at first no neighbors have been encountered
304304 first_visit_to_tree = fill ((0 , 0 ), ne)
305- forest = DisjointSets {Tuple{Int,Int}} ()
306- sizehint! (forest. intmap, ne)
307- sizehint! (forest. revmap, ne)
308- sizehint! (forest. internal. parents, ne)
309- sizehint! (forest. internal. ranks, ne)
305+ forest = Forest {Int} (ne)
310306 vertices_in_order = vertices (g, order)
311307
312308 for v in vertices_in_order
@@ -347,7 +343,7 @@ function acyclic_coloring(g::AdjacencyGraph, order::AbstractOrder; postprocessin
347343 end
348344
349345 # compress forest
350- for edge in forest. revmap
346+ for edge in keys ( forest. intmap)
351347 find_root! (forest, edge)
352348 end
353349 tree_set = TreeSet (forest, nb_vertices (g))
@@ -367,11 +363,10 @@ function _prevent_cycle!(
367363 # modified
368364 first_visit_to_tree:: AbstractVector{<:Tuple} ,
369365 forbidden_colors:: AbstractVector{<:Integer} ,
370- forest:: DisjointSets {<:Tuple{Int,Int} } ,
366+ forest:: Forest {<:Integer } ,
371367)
372368 wx = _sort (w, x)
373- root = find_root! (forest, wx) # edge wx belongs to the 2-colored tree T represented by edge "root"
374- id = forest. intmap[root] # ID of the representative edge "root" of a two-colored tree T.
369+ id = find_root! (forest, wx) # The edge wx belongs to the 2-colored tree T, represented by an edge with an integer ID
375370 (p, q) = first_visit_to_tree[id]
376371 if p != v # T is being visited from vertex v for the first time
377372 vw = _sort (v, w)
@@ -389,7 +384,7 @@ function _grow_star!(
389384 color:: AbstractVector{<:Integer} ,
390385 # modified
391386 first_neighbor:: AbstractVector{<:Tuple} ,
392- forest:: DisjointSets{Tuple{Int,Int} } ,
387+ forest:: Forest{<:Integer } ,
393388)
394389 vw = _sort (v, w)
395390 push! (forest, vw) # Create a new tree T_{vw} consisting only of edge vw
@@ -412,7 +407,7 @@ function _merge_trees!(
412407 w:: Integer ,
413408 x:: Integer ,
414409 # modified
415- forest:: DisjointSets{Tuple{Int,Int} } ,
410+ forest:: Forest{<:Integer } ,
416411)
417412 vw = _sort (v, w)
418413 wx = _sort (w, x)
@@ -438,12 +433,11 @@ struct TreeSet
438433 is_star:: Vector{Bool}
439434end
440435
441- function TreeSet (forest:: DisjointSets{Tuple{ Int,Int} } , nvertices:: Int )
442- # forest is a structure DisjointSets from DataStructures .jl
436+ function TreeSet (forest:: Forest{ Int} , nvertices:: Int )
437+ # Forest is a structure defined in forest .jl
443438 # - forest.intmap: a dictionary that maps an edge (i, j) to an integer k
444- # - forest.revmap: a dictionary that does the reverse of intmap, mapping an integer k to an edge (i, j)
445- # - forest.internal.ngroups: the number of trees in the forest
446- ntrees = forest. internal. ngroups
439+ # - forest.ntrees: the number of trees in the forest
440+ ntrees = forest. ntrees
447441
448442 # dictionary that maps a tree's root to the index of the tree
449443 roots = Dict {Int,Int} ()
@@ -454,11 +448,9 @@ function TreeSet(forest::DisjointSets{Tuple{Int,Int}}, nvertices::Int)
454448
455449 # counter of the number of roots found
456450 k = 0
457- for edge in forest. revmap
451+ for edge in keys ( forest. intmap)
458452 i, j = edge
459- # forest has already been compressed so this doesn't change its state
460- root_edge = find_root! (forest, edge)
461- root = forest. intmap[root_edge]
453+ root = find_root! (forest, edge)
462454
463455 # Update roots
464456 if ! haskey (roots, root)
0 commit comments