@@ -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
@@ -346,10 +342,6 @@ function acyclic_coloring(g::AdjacencyGraph, order::AbstractOrder; postprocessin
346342 end
347343 end
348344
349- # compress forest
350- for edge in forest. revmap
351- find_root! (forest, edge)
352- end
353345 tree_set = TreeSet (forest, nb_vertices (g))
354346 if postprocessing
355347 # Reuse the vector forbidden_colors to compute offsets during post-processing
@@ -367,11 +359,10 @@ function _prevent_cycle!(
367359 # modified
368360 first_visit_to_tree:: AbstractVector{<:Tuple} ,
369361 forbidden_colors:: AbstractVector{<:Integer} ,
370- forest:: DisjointSets {<:Tuple{Int,Int} } ,
362+ forest:: Forest {<:Integer } ,
371363)
372364 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.
365+ id = find_root! (forest, wx) # The edge wx belongs to the 2-colored tree T, represented by an edge with an integer ID
375366 (p, q) = first_visit_to_tree[id]
376367 if p != v # T is being visited from vertex v for the first time
377368 vw = _sort (v, w)
@@ -389,7 +380,7 @@ function _grow_star!(
389380 color:: AbstractVector{<:Integer} ,
390381 # modified
391382 first_neighbor:: AbstractVector{<:Tuple} ,
392- forest:: DisjointSets{Tuple{Int,Int} } ,
383+ forest:: Forest{<:Integer } ,
393384)
394385 vw = _sort (v, w)
395386 push! (forest, vw) # Create a new tree T_{vw} consisting only of edge vw
@@ -412,7 +403,7 @@ function _merge_trees!(
412403 w:: Integer ,
413404 x:: Integer ,
414405 # modified
415- forest:: DisjointSets{Tuple{Int,Int} } ,
406+ forest:: Forest{<:Integer } ,
416407)
417408 vw = _sort (v, w)
418409 wx = _sort (w, x)
@@ -438,27 +429,24 @@ struct TreeSet
438429 is_star:: Vector{Bool}
439430end
440431
441- function TreeSet (forest:: DisjointSets{Tuple{ Int,Int} } , nvertices:: Int )
442- # forest is a structure DisjointSets from DataStructures .jl
432+ function TreeSet (forest:: Forest{ Int} , nvertices:: Int )
433+ # Forest is a structure defined in forest .jl
443434 # - 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
435+ # - forest.num_trees: the number of trees in the forest
436+ nt = forest. num_trees
447437
448438 # dictionary that maps a tree's root to the index of the tree
449439 roots = Dict {Int,Int} ()
450- sizehint! (roots, ntrees )
440+ sizehint! (roots, nt )
451441
452442 # vector of dictionaries where each dictionary stores the neighbors of each vertex in a tree
453- trees = [Dict {Int,Vector{Int}} () for i in 1 : ntrees ]
443+ trees = [Dict {Int,Vector{Int}} () for i in 1 : nt ]
454444
455445 # counter of the number of roots found
456446 k = 0
457- for edge in forest. revmap
447+ for edge in keys ( forest. intmap)
458448 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]
449+ root = find_root! (forest, edge)
462450
463451 # Update roots
464452 if ! haskey (roots, root)
@@ -488,11 +476,11 @@ function TreeSet(forest::DisjointSets{Tuple{Int,Int}}, nvertices::Int)
488476 degrees = Vector {Int} (undef, nvertices)
489477
490478 # reverse breadth first (BFS) traversal order for each tree in the forest
491- reverse_bfs_orders = [Tuple{Int,Int}[] for i in 1 : ntrees ]
479+ reverse_bfs_orders = [Tuple{Int,Int}[] for i in 1 : nt ]
492480
493481 # nvmax is the number of vertices of the biggest tree in the forest
494482 nvmax = 0
495- for k in 1 : ntrees
483+ for k in 1 : nt
496484 nb_vertices_tree = length (trees[k])
497485 nvmax = max (nvmax, nb_vertices_tree)
498486 end
@@ -502,9 +490,9 @@ function TreeSet(forest::DisjointSets{Tuple{Int,Int}}, nvertices::Int)
502490
503491 # Specify if each tree in the forest is a star,
504492 # meaning that one vertex is directly connected to all other vertices in the tree
505- is_star = Vector {Bool} (undef, ntrees )
493+ is_star = Vector {Bool} (undef, nt )
506494
507- for k in 1 : ntrees
495+ for k in 1 : nt
508496 tree = trees[k]
509497
510498 # Boolean indicating whether the current tree is a star (a single central vertex connected to all others)
0 commit comments