@@ -332,7 +332,7 @@ function acyclic_coloring(g::AdjacencyGraph, order::AbstractOrder; postprocessin
332332 iszero (color[x]) && continue
333333 if forbidden_colors[color[x]] != v
334334 _prevent_cycle! (
335- v, w, x, color, first_visit_to_tree, forbidden_colors, forest
335+ v, w, x, color, g, first_visit_to_tree, forbidden_colors, forest
336336 )
337337 end
338338 end
@@ -345,14 +345,14 @@ function acyclic_coloring(g::AdjacencyGraph, order::AbstractOrder; postprocessin
345345 end
346346 for w in neighbors (g, v) # grow two-colored stars around the vertex v
347347 iszero (color[w]) && continue
348- _grow_star! (v, w, color, first_neighbor, forest)
348+ _grow_star! (v, w, color, g, first_neighbor, forest)
349349 end
350350 for w in neighbors (g, v)
351351 iszero (color[w]) && continue
352352 for x in neighbors (g, w)
353353 (x == v || iszero (color[x])) && continue
354354 if color[x] == color[v]
355- _merge_trees! (v, w, x, forest) # merge trees T₁ ∋ vw and T₂ ∋ wx if T₁ != T₂
355+ _merge_trees! (v, w, x, g, forest) # merge trees T₁ ∋ vw and T₂ ∋ wx if T₁ != T₂
356356 end
357357 end
358358 end
@@ -373,12 +373,14 @@ function _prevent_cycle!(
373373 x:: Integer ,
374374 color:: AbstractVector{<:Integer} ,
375375 # modified
376+ g:: AdjacencyGraph ,
376377 first_visit_to_tree:: AbstractVector{<:Tuple} ,
377378 forbidden_colors:: AbstractVector{<:Integer} ,
378379 forest:: Forest{<:Integer} ,
379380)
380381 wx = _sort (w, x)
381- id = find_root! (forest, wx) # The edge wx belongs to the 2-colored tree T, represented by an edge with an integer ID
382+ index_wx = g. M[wx... ]
383+ id = find_root! (forest, index_wx) # The edge wx belongs to the 2-colored tree T, represented by an edge with an integer ID
382384 (p, q) = first_visit_to_tree[id]
383385 if p != v # T is being visited from vertex v for the first time
384386 vw = _sort (v, w)
@@ -395,6 +397,7 @@ function _grow_star!(
395397 w:: Integer ,
396398 color:: AbstractVector{<:Integer} ,
397399 # modified
400+ g:: AdjacencyGraph ,
398401 first_neighbor:: AbstractVector{<:Tuple} ,
399402 forest:: Forest{<:Integer} ,
400403)
@@ -406,8 +409,10 @@ function _grow_star!(
406409 else # merge T_{vw} with a two-colored star being grown around v
407410 vw = _sort (v, w)
408411 pq = _sort (p, q)
409- root1 = find_root! (forest, vw)
410- root2 = find_root! (forest, pq)
412+ index_vw = g. M[vw... ]
413+ index_pq = g. M[pq... ]
414+ root1 = find_root! (forest, index_vw)
415+ root2 = find_root! (forest, index_pq)
411416 root_union! (forest, root1, root2)
412417 end
413418 return nothing
@@ -419,12 +424,15 @@ function _merge_trees!(
419424 w:: Integer ,
420425 x:: Integer ,
421426 # modified
427+ g:: AdjacencyGraph ,
422428 forest:: Forest{<:Integer} ,
423429)
424430 vw = _sort (v, w)
425431 wx = _sort (w, x)
426- root1 = find_root! (forest, vw)
427- root2 = find_root! (forest, wx)
432+ index_vw = g. M[vw... ]
433+ index_wx = g. M[wx... ]
434+ root1 = find_root! (forest, index_vw)
435+ root2 = find_root! (forest, index_wx)
428436 if root1 != root2
429437 root_union! (forest, root1, root2)
430438 end
@@ -445,10 +453,8 @@ struct TreeSet
445453 is_star:: Vector{Bool}
446454end
447455
448- function TreeSet (forest:: Forest{Int} , nvertices:: Int )
449- # Forest is a structure defined in forest.jl
450- # - forest.intmap: a dictionary that maps an edge (i, j) to an integer k
451- # - forest.num_trees: the number of trees in the forest
456+ function TreeSet (g:: AdjacencyGraph{Int} , forest:: Forest{Int} , nvertices:: Int )
457+ # he number of trees in the forest
452458 nt = forest. num_trees
453459
454460 # dictionary that maps a tree's root to the index of the tree
@@ -462,7 +468,8 @@ function TreeSet(forest::Forest{Int}, nvertices::Int)
462468 k = 0
463469 for edge in keys (forest. intmap)
464470 i, j = edge
465- root = find_root! (forest, edge)
471+ edge_index = g. M[edge... ]
472+ root = find_root! (forest, edge_index)
466473
467474 # Update roots
468475 if ! haskey (roots, root)
@@ -576,7 +583,7 @@ function TreeSet(forest::Forest{Int}, nvertices::Int)
576583 is_star[k] = bool_star
577584 end
578585
579- return TreeSet (reverse_bfs_orders, is_star)
586+ return TreeSet (g, reverse_bfs_orders, is_star)
580587end
581588
582589# # Postprocessing, mirrors decompression code
0 commit comments