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
# Create a list of spokes for each star, preallocating their sizes based on nb_spokes
152
156
spokes = [Vector{Int}(undef, ns) for ns in nb_spokes]
153
157
154
158
# Reuse nb_spokes as counters to track the current index while filling the spokes
155
159
fill!(nb_spokes, 0)
156
160
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
161
+
nv =nb_vertices(g)
162
+
k =0
163
+
rows =rowvals(g.M)
164
+
for j in1:nv
165
+
for p innzrange(g.M, j)
166
+
i = rows[p]
167
+
k +=1
168
+
s = star[k]
169
+
h =abs(hub[s])
170
+
nb_spokes[s] +=1
171
+
index = nb_spokes[s]
172
+
173
+
# Assign the non-hub vertex (spoke) to the correct position in spokes
174
+
if i == h
175
+
spokes[s][index] = j
176
+
elseif j == h
177
+
spokes[s][index] = i
178
+
end
167
179
end
168
180
end
169
-
returnStarSet(star, hub, spokes)
181
+
returnStarSet(star, hub, spokes, g.M)
170
182
end
171
183
172
184
_sort(u, v) = (min(u, v), max(u, v))
@@ -191,7 +203,7 @@ end
191
203
192
204
function_update_stars!(
193
205
# modified
194
-
star::Dict{<:Tuple,<:Integer},
206
+
star::AbstractVector{<:Integer},
195
207
hub::AbstractVector{<:Integer},
196
208
nb_spokes::AbstractVector{<:Integer},
197
209
# not modified
@@ -203,14 +215,16 @@ function _update_stars!(
203
215
for w inneighbors(g, v)
204
216
iszero(color[w]) &&continue
205
217
vw =_sort(v, w)
218
+
index_vw = g.M[vw...]
206
219
x_exists =false
207
220
for x inneighbors(g, w)
208
221
if x != v && color[x] == color[v] # vw, wx ∈ E
209
222
wx =_sort(w, x)
210
-
star_wx = star[wx]
223
+
index_wx = g.M[wx...]
224
+
star_wx = star[index_wx]
211
225
hub[star_wx] = w # this may already be true
212
226
nb_spokes[star_wx] +=1
213
-
star[vw] = star_wx
227
+
star[index_vw] = star_wx
214
228
x_exists =true
215
229
break
216
230
end
@@ -219,14 +233,15 @@ function _update_stars!(
219
233
(p, q) = first_neighbor[color[w]]
220
234
if p == v && q != w # vw, vq ∈ E and color[w] = color[q]
221
235
vq =_sort(v, q)
222
-
star_vq = star[vq]
236
+
index_vq = g.M[vq...]
237
+
star_vq = star[index_vq]
223
238
hub[star_vq] = v # this may already be true
224
239
nb_spokes[star_vq] +=1
225
-
star[vw] = star_vq
240
+
star[index_vw] = star_vq
226
241
else# vw forms a new star
227
242
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
243
push!(nb_spokes, 1)
229
-
star[vw] =length(hub)
244
+
star[index_vw] =length(hub)
230
245
end
231
246
end
232
247
end
@@ -251,7 +266,7 @@ This function corresponds to algorithm `DirectRecover2` in the paper.
0 commit comments