You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update decompression_single_color! for star coloring (#217)
* Update decompression_single_color! for star coloring
* Remove the vector spokes
* Update src/decompression.jl
---------
Co-authored-by: Guillaume Dalle <22795598+gdalle@users.noreply.github.com>
# Create a list of spokes for each star, preallocating their sizes based on nb_spokes
152
-
spokes = [Vector{Int}(undef, ns) for ns in nb_spokes]
153
-
154
-
# Reuse nb_spokes as counters to track the current index while filling the spokes
155
-
fill!(nb_spokes, 0)
156
-
157
-
for ((i, j), s) inpairs(star)
158
-
h =abs(hub[s])
159
-
nb_spokes[s] +=1
160
-
index = nb_spokes[s]
161
-
162
-
# Assign the non-hub vertex (spoke) to the correct position in spokes
163
-
if i == h
164
-
spokes[s][index] = j
165
-
elseif j == h
166
-
spokes[s][index] = i
167
-
end
168
-
end
169
-
returnStarSet(star, hub, spokes)
170
145
end
171
146
172
147
_sort(u, v) = (min(u, v), max(u, v))
@@ -193,7 +168,6 @@ function _update_stars!(
193
168
# modified
194
169
star::Dict{<:Tuple,<:Integer},
195
170
hub::AbstractVector{<:Integer},
196
-
nb_spokes::AbstractVector{<:Integer},
197
171
# not modified
198
172
g::AdjacencyGraph,
199
173
v::Integer,
@@ -209,7 +183,6 @@ function _update_stars!(
209
183
wx =_sort(w, x)
210
184
star_wx = star[wx]
211
185
hub[star_wx] = w # this may already be true
212
-
nb_spokes[star_wx] +=1
213
186
star[vw] = star_wx
214
187
x_exists =true
215
188
break
@@ -221,11 +194,9 @@ function _update_stars!(
221
194
vq =_sort(v, q)
222
195
star_vq = star[vq]
223
196
hub[star_vq] = v # this may already be true
224
-
nb_spokes[star_vq] +=1
225
197
star[vw] = star_vq
226
198
else# vw forms a new star
227
199
push!(hub, -max(v, w)) # star is trivial (composed only of two vertices) so we set the hub to a negative value, but it allows us to choose one of the two vertices
228
-
push!(nb_spokes, 1)
229
200
star[vw] =length(hub)
230
201
end
231
202
end
@@ -586,7 +557,7 @@ function postprocess!(
586
557
587
558
if star_or_tree_set isa StarSet
588
559
# only the colors of the hubs are used
589
-
(; hub, spokes) = star_or_tree_set
560
+
(; star, hub) = star_or_tree_set
590
561
nb_trivial_stars =0
591
562
592
563
# Iterate through all non-trivial stars
@@ -601,19 +572,17 @@ function postprocess!(
601
572
602
573
# Process the trivial stars (if any)
603
574
if nb_trivial_stars >0
604
-
for s ineachindex(hub)
605
-
j = hub[s]
606
-
if j <0
607
-
i = spokes[s][1]
608
-
j =abs(j)
609
-
if color_used[color[i]]
610
-
# Make i the hub to avoid possibly adding one more used color
611
-
# Switch it with the (only) spoke
612
-
hub[s] = i
613
-
spokes[s][1] = j
575
+
for ((i, j), s) inpairs(star)
576
+
h = hub[s]
577
+
if h <0
578
+
h =abs(h)
579
+
spoke = i == h ? j : i
580
+
if color_used[color[spoke]]
581
+
# Switch the hub and the spoke to possibly avoid adding one more used color
0 commit comments