Skip to content

Commit 87fd1b3

Browse files
authored
Improve degree-based order implementation (#223)
1 parent b465a79 commit 87fd1b3

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/order.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,39 +210,39 @@ function update_bucket!(db::DegreeBuckets, v::Integer; degtype, direction)
210210
low, high = bucket_low[d + 1], bucket_high[d + 1]
211211
# select previous or next bucket for the move
212212
if degree_increasing(; degtype, direction)
213-
# put v at the end of its bucket by swapping
213+
# move the vertex w located at the end of the current bucket to v's position
214214
w = bucket_storage[high]
215215
bucket_storage[p] = w
216-
bucket_storage[high] = v
217216
positions[w] = p
218-
positions[v] = high
219-
# move v to the beginning of the next bucket (mind the gap)
217+
# shrink current bucket from the right
218+
# morally we put v at the end and then ignore it
219+
bucket_high[d + 1] -= 1
220+
# move v to the beginning of the next bucket (!= ColPack)
220221
d_new = d + 1
221222
low_new, high_new = bucket_low[d_new + 1], bucket_high[d_new + 1]
222223
bucket_storage[low_new - 1] = v
223-
# update v stats
224+
# grow next bucket to the left
225+
bucket_low[d_new + 1] -= 1
226+
# update v's stats
224227
degrees[v] = d_new
225228
positions[v] = low_new - 1
226-
# grow next bucket to the left, shrink current one from the right
227-
bucket_low[d_new + 1] -= 1
228-
bucket_high[d + 1] -= 1
229229
else
230-
# put v at the beginning of its bucket by swapping
230+
# move the vertex w located at the start of the current bucket to v's position (!= ColPack)
231231
w = bucket_storage[low]
232232
bucket_storage[p] = w
233-
bucket_storage[low] = v
234233
positions[w] = p
235-
positions[v] = low
236-
# move v to the end of the previous bucket (mind the gap)
234+
# shrink current bucket from the left
235+
# morally we put v at the start and then ignore it
236+
bucket_low[d + 1] += 1
237+
# move v to the end of the previous bucket
237238
d_new = d - 1
238239
low_new, high_new = bucket_low[d_new + 1], bucket_high[d_new + 1]
239240
bucket_storage[high_new + 1] = v
240-
# update v stats
241+
# grow previous bucket to the right
242+
bucket_high[d_new + 1] += 1
243+
# update v's stats
241244
degrees[v] = d_new
242245
positions[v] = high_new + 1
243-
# grow previous bucket to the right, shrink current one from the left
244-
bucket_high[d_new + 1] += 1
245-
bucket_low[d + 1] += 1
246246
end
247247
return nothing
248248
end

0 commit comments

Comments
 (0)