@@ -82,18 +82,18 @@ function star_coloring(g::AdjacencyGraph, order::AbstractOrder, postprocessing::
8282 nv = nb_vertices (g)
8383 ne = nb_edges (g)
8484 color = zeros (Int, nv)
85- forbidden_colors = zeros (Int, nv)
86- edge_to_index = build_edge_to_index (S, forbidden_colors )
85+ forbidden_colors = g . vertex_buffer # Vector of length nv
86+ fill! (forbidden_colors, 0 )
8787 first_neighbor = fill ((0 , 0 , 0 ), nv) # at first no neighbors have been encountered
8888 treated = zeros (Int, nv)
8989 star = Vector {Int} (undef, ne)
9090 hub = Int[] # one hub for each star, including the trivial ones
9191 vertices_in_order = vertices (g, order)
9292
9393 for v in vertices_in_order
94- for (iw, w ) in enumerate ( neighbors2 ( g, v) )
95- ( v == w || iszero (color[w])) && continue
96- index_vw = edge_to_index[S . colptr[v] + iw - 1 ]
94+ for (w, index_vw ) in neighbors_with_edge_indices ( g, v)
95+ ! has_diagonal (g) || ( v == w && continue )
96+ iszero (color[w]) && continue
9797 forbidden_colors[color[w]] = v
9898 (p, q, _) = first_neighbor[color[w]]
9999 if p == v # Case 1
@@ -105,9 +105,9 @@ function star_coloring(g::AdjacencyGraph, order::AbstractOrder, postprocessing::
105105 _treat! (treated, forbidden_colors, g, v, w, color)
106106 else
107107 first_neighbor[color[w]] = (v, w, index_vw)
108- for (ix, x ) in enumerate ( neighbors2 ( g, w) )
109- (w == x || x == v || iszero (color[x])) && continue
110- index_wx = edge_to_index[S . colptr[w] + ix - 1 ]
108+ for (x, index_wx ) in neighbors_with_edge_indices ( g, w)
109+ ! has_diagonal (g) || (w == x && continue )
110+ (x == v || iszero (color[x])) && continue
111111 if x == hub[star[index_wx]] # potential Case 2 (which is always false for trivial stars with two vertices, since the associated hub is negative)
112112 forbidden_colors[color[x]] = v
113113 end
@@ -120,14 +120,13 @@ function star_coloring(g::AdjacencyGraph, order::AbstractOrder, postprocessing::
120120 break
121121 end
122122 end
123- _update_stars! (star, hub, g, v, color, first_neighbor, edge_to_index )
123+ _update_stars! (star, hub, g, v, color, first_neighbor)
124124 end
125125 star_set = StarSet (star, hub)
126126 if postprocessing
127- # Reuse the vector forbidden_colors to compute offsets during post-processing
128- postprocess! (color, star_set, g, forbidden_colors, edge_to_index)
127+ postprocess! (color, star_set, g)
129128 end
130- return color, star_set, edge_to_index
129+ return color, star_set
131130end
132131
133132function _treat! (
@@ -141,6 +140,7 @@ function _treat!(
141140 color:: AbstractVector{<:Integer} ,
142141)
143142 for x in neighbors (g, w)
143+ ! has_diagonal (g) || (w == x && continue )
144144 iszero (color[x]) && continue
145145 forbidden_colors[color[x]] = v
146146 end
@@ -157,17 +157,15 @@ function _update_stars!(
157157 v:: Integer ,
158158 color:: AbstractVector{<:Integer} ,
159159 first_neighbor:: AbstractVector{<:Tuple} ,
160- edge_to_index:: AbstractVector{<:Integer} ,
161160)
162161 S = pattern (g)
163- for (iw, w ) in enumerate ( neighbors2 ( g, v) )
164- ( v == w || iszero (color[w])) && continue
165- index_vw = edge_to_index[S . colptr[v] + iw - 1 ]
162+ for (w, index_vw ) in neighbors_with_edge_indices ( g, v)
163+ ! has_diagonal (g) || ( v == w && continue )
164+ iszero (color[w]) && continue
166165 x_exists = false
167- for (ix, x ) in enumerate ( neighbors2 ( g, w) )
168- ( w == x) && continue
166+ for (x, index_wx ) in neighbors_with_edge_indices ( g, w)
167+ ! has_diagonal (g) || ( w == x && continue )
169168 if x != v && color[x] == color[v] # vw, wx ∈ E
170- index_wx = edge_to_index[S. colptr[w] + ix - 1 ]
171169 star_wx = star[index_wx]
172170 hub[star_wx] = w # this may already be true
173171 star[index_vw] = star_wx
@@ -235,24 +233,26 @@ function acyclic_coloring(g::AdjacencyGraph, order::AbstractOrder, postprocessin
235233 nv = nb_vertices (g)
236234 ne = nb_edges (g)
237235 color = zeros (Int, nv)
238- forbidden_colors = zeros (Int, nv)
239- edge_to_index = build_edge_to_index (S, forbidden_colors )
236+ forbidden_colors = g . vertex_buffer # Vector of length nv
237+ fill! (forbidden_colors, 0 )
240238 first_neighbor = fill ((0 , 0 , 0 ), nv) # at first no neighbors have been encountered
241239 first_visit_to_tree = fill ((0 , 0 ), ne)
242240 forest = Forest {Int} (ne)
243241 vertices_in_order = vertices (g, order)
244242
245243 for v in vertices_in_order
246244 for w in neighbors (g, v)
245+ ! has_diagonal (g) || (v == w && continue )
247246 iszero (color[w]) && continue
248247 forbidden_colors[color[w]] = v
249248 end
250249 for w in neighbors (g, v)
250+ ! has_diagonal (g) || (v == w && continue )
251251 iszero (color[w]) && continue
252- for (ix, x) in enumerate (neighbors2 (g, w))
253- (w == x || iszero (color[x])) && continue
252+ for (x, index_wx) in neighbors_with_edge_indices (g, w)
253+ ! has_diagonal (g) || (w == x && continue )
254+ iszero (color[x]) && continue
254255 if forbidden_colors[color[x]] != v
255- index_wx = edge_to_index[S. colptr[w] + ix - 1 ]
256256 _prevent_cycle! (
257257 v,
258258 w,
@@ -272,28 +272,27 @@ function acyclic_coloring(g::AdjacencyGraph, order::AbstractOrder, postprocessin
272272 break
273273 end
274274 end
275- for (iw, w ) in enumerate ( neighbors2 ( g, v) ) # grow two-colored stars around the vertex v
276- ( v == w || iszero (color[w])) && continue
277- index_vw = edge_to_index[S . colptr[v] + iw - 1 ]
275+ for (w, index_vw ) in neighbors_with_edge_indices ( g, v) # grow two-colored stars around the vertex v
276+ ! has_diagonal (g) || ( v == w && continue )
277+ iszero (color[w]) && continue
278278 _grow_star! (v, w, index_vw, color, first_neighbor, forest)
279279 end
280- for (iw, w) in enumerate (neighbors2 (g, v))
281- (v == w || iszero (color[w])) && continue
282- for (ix, x) in enumerate (neighbors2 (g, w))
283- (w == x || x == v || iszero (color[x])) && continue
280+ for (w, index_vw) in neighbors_with_edge_indices (g, v)
281+ ! has_diagonal (g) || (v == w && continue )
282+ iszero (color[w]) && continue
283+ for (x, index_wx) in neighbors_with_edge_indices (g, w)
284+ ! has_diagonal (g) || (w == x && continue )
285+ (x == v || iszero (color[x])) && continue
284286 if color[x] == color[v]
285- index_vw = edge_to_index[S. colptr[v] + iw - 1 ]
286- index_wx = edge_to_index[S. colptr[w] + ix - 1 ]
287287 _merge_trees! (v, w, x, index_vw, index_wx, forest) # merge trees T₁ ∋ vw and T₂ ∋ wx if T₁ != T₂
288288 end
289289 end
290290 end
291291 end
292292
293- tree_set = TreeSet (g, forest, edge_to_index )
293+ tree_set = TreeSet (g, forest)
294294 if postprocessing
295- # Reuse the vector forbidden_colors to compute offsets during post-processing
296- postprocess! (color, tree_set, g, forbidden_colors, edge_to_index)
295+ postprocess! (color, tree_set, g)
297296 end
298297 return color, tree_set
299298end
@@ -374,8 +373,9 @@ struct TreeSet
374373 is_star:: Vector{Bool}
375374end
376375
377- function TreeSet (g:: AdjacencyGraph , forest:: Forest{Int} , edge_to_index :: Vector{Int} )
376+ function TreeSet (g:: AdjacencyGraph , forest:: Forest{Int} )
378377 S = pattern (g)
378+ edge_to_index = edge_indices (g)
379379 nv = nb_vertices (g)
380380 nt = forest. num_trees
381381
@@ -520,10 +520,9 @@ function postprocess!(
520520 color:: AbstractVector{<:Integer} ,
521521 star_or_tree_set:: Union{StarSet,TreeSet} ,
522522 g:: AdjacencyGraph ,
523- offsets:: Vector{Int} ,
524- edge_to_index:: Vector{Int} ,
525523)
526- (; S) = g
524+ S = pattern (g)
525+ edge_to_index = edge_indices (g)
527526 # flag which colors are actually used during decompression
528527 nb_colors = maximum (color)
529528 color_used = zeros (Bool, nb_colors)
@@ -553,7 +552,6 @@ function postprocess!(
553552 end
554553
555554 # Process the trivial stars (if any)
556- # TODO : Should we compute "compressed_indices" in the same time?
557555 if nb_trivial_stars > 0
558556 rvS = rowvals (S)
559557 for j in axes (S, 2 )
@@ -626,6 +624,7 @@ function postprocess!(
626624
627625 # if at least one of the colors is useless, modify the color assignments of vertices
628626 if any (! , color_used)
627+ offsets = g. vertex_buffer
629628 num_colors_useless = 0
630629
631630 # determine what are the useless colors and compute the offsets
0 commit comments