66
77module Coloring
88
9- import DataStructures
10-
9+ include (" Forest.jl" )
1110include (" topological_sort.jl" )
1211
1312"""
@@ -154,7 +153,7 @@ function _prevent_cycle(
154153 forbiddenColors,
155154 color,
156155)
157- er = DataStructures . find_root ! (S, e_idx2)
156+ er = _find_root ! (S, e_idx2)
158157 @inbounds first = firstVisitToTree[er]
159158 p = first. source # but this depends on the order?
160159 q = first. target
@@ -172,29 +171,18 @@ function _grow_star(v, w, e_idx, firstNeighbor, color, S)
172171 @inbounds if p != v
173172 firstNeighbor[color[w]] = _Edge (e_idx, v, w)
174173 else
175- union ! (S, e_idx, e. index)
174+ _root_union ! (S, e_idx, e. index)
176175 end
177176 return
178177end
179178
180- function _merge_trees (eg, eg1, S)
181- e1 = DataStructures. find_root! (S, eg)
182- e2 = DataStructures. find_root! (S, eg1)
183- if e1 != e2
184- union! (S, eg, eg1)
179+ function _merge_trees (S:: _Forest , eg:: Int , eg1:: Int )
180+ if _find_root! (S, eg) != _find_root! (S, eg1)
181+ _root_union! (S, eg, eg1)
185182 end
186183 return
187184end
188185
189- # Work-around a deprecation in DataStructures@0.19
190- function _IntDisjointSet (n)
191- @static if isdefined (DataStructures, :IntDisjointSet )
192- return DataStructures. IntDisjointSet (n)
193- else
194- return DataStructures. IntDisjointSets (n) # COV_EXCL_LINE
195- end
196- end
197-
198186"""
199187 acyclic_coloring(g::UndirectedGraph)
200188
@@ -214,8 +202,7 @@ function acyclic_coloring(g::UndirectedGraph)
214202 firstNeighbor = _Edge[]
215203 firstVisitToTree = fill (_Edge (0 , 0 , 0 ), _num_edges (g))
216204 color = fill (0 , _num_vertices (g))
217- # disjoint set forest of edges in the graph
218- S = _IntDisjointSet (_num_edges (g))
205+ S = _Forest (_num_edges (g))
219206 @inbounds for v in 1 : _num_vertices (g)
220207 n_neighbor = _num_neighbors (v, g)
221208 start_neighbor = _start_neighbors (v, g)
@@ -293,7 +280,7 @@ function acyclic_coloring(g::UndirectedGraph)
293280 continue
294281 end
295282 if color[x] == color[v]
296- _merge_trees (e_idx, e2_idx, S )
283+ _merge_trees (S, e_idx, e2_idx )
297284 end
298285 end
299286 end
0 commit comments