Skip to content

Commit fc9d63a

Browse files
authored
Update how we use visited_trees in TreeSet (#245)
1 parent 71ba02b commit fc9d63a

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/coloring.jl

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,9 @@ function TreeSet(
450450
neighbor_position[k] = neighbor_position[k - 1] + 2 * tree_edge_indices[k]
451451
end
452452

453-
# found_in_tree indicates if a given vertex is in each tree
454-
found_in_tree = fill(false, nt)
453+
# Record the most recent vertex from which each tree is visited
454+
visited_trees = zeros(T, nt)
455455

456-
# Maintain a record of visited trees to efficiently reset found_in_tree
457-
visited_trees = Vector{T}(undef, nt)
458-
459-
# Number of trees visited for each column of S
460-
nt_visited = 0
461456
rvS = rowvals(S)
462457
for j in axes(S, 2)
463458
for pos in nzrange(S, j)
@@ -474,13 +469,9 @@ function TreeSet(
474469
# Position in tree_vertices where vertex j should be found or inserted
475470
vertex_index = vertex_position[index_tree]
476471

477-
if !found_in_tree[index_tree]
478-
# Mark that vertex j is present in the current tree
479-
found_in_tree[index_tree] = true
480-
481-
# This is the first time an edge with vertex j has been found in the tree
482-
nt_visited += 1
483-
visited_trees[nt_visited] = index_tree
472+
if visited_trees[index_tree] != j
473+
# Mark the current tree as visited from vertex j
474+
visited_trees[index_tree] = j
484475

485476
# Insert j into tree_vertices
486477
vertex_position[index_tree] += 1
@@ -497,12 +488,6 @@ function TreeSet(
497488
tree_neighbor_indices[vertex_index + 1] += 1
498489
end
499490
end
500-
501-
# Reset found_in_tree
502-
for t in 1:nt_visited
503-
found_in_tree[visited_trees[t]] = false
504-
end
505-
nt_visited = 0
506491
end
507492

508493
# Compute a shifted cumulative sum of tree_edge_indices, starting from one
@@ -528,7 +513,7 @@ function TreeSet(
528513

529514
# Determine if each tree in the forest is a star
530515
# In a star, at most one vertex has a degree strictly greater than one
531-
is_star = found_in_tree
516+
is_star = Vector{Bool}(undef, nt)
532517

533518
# Number of edges treated
534519
num_edges_treated = zero(T)

0 commit comments

Comments
 (0)