Skip to content

Commit a554e3c

Browse files
committed
Update coloring.jl
1 parent e639861 commit a554e3c

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/coloring.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,15 @@ function TreeSet(
452452

453453
# found_in_tree indicates if a given vertex is in each tree
454454
found_in_tree = Vector{Bool}(undef, nt)
455+
fill!(found_in_tree, false)
456+
457+
# Maintain a record of visited trees to efficiently reset found_in_tree
458+
visited_trees = Vector{T}(undef, nt)
455459

456460
rvS = rowvals(S)
457461
for j in axes(S, 2)
458-
# Reset the vector found_in_tree to indicate that the vertex j is not present in any tree yet
459-
fill!(found_in_tree, false)
462+
# Number of visited trees that contain vertex j
463+
ntree_visited = 0
460464

461465
for pos in nzrange(S, j)
462466
i = rvS[pos]
@@ -476,6 +480,10 @@ function TreeSet(
476480
# Mark that vertex j is present in the current tree
477481
found_in_tree[index_tree] = true
478482

483+
# This is the first time an edge with vertex j has been found in the tree
484+
nt_visited += 1
485+
visited_trees[nt_visited] = index_tree
486+
479487
# Insert j into tree_vertices
480488
vertex_position[index_tree] += 1
481489
vertex_index += 1
@@ -491,6 +499,11 @@ function TreeSet(
491499
tree_neighbor_indices[vertex_index + 1] += 1
492500
end
493501
end
502+
503+
# Reset found_in_tree
504+
for t in 1:nt_visited
505+
found_in_tree[visited_trees[t]] = false
506+
end
494507
end
495508

496509
# Compute a shifted cumulative sum of tree_edge_indices, starting from one

0 commit comments

Comments
 (0)