@@ -450,14 +450,9 @@ function TreeSet(
450
450
neighbor_position[k] = neighbor_position[k - 1 ] + 2 * tree_edge_indices[k]
451
451
end
452
452
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)
455
455
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
461
456
rvS = rowvals (S)
462
457
for j in axes (S, 2 )
463
458
for pos in nzrange (S, j)
@@ -474,13 +469,9 @@ function TreeSet(
474
469
# Position in tree_vertices where vertex j should be found or inserted
475
470
vertex_index = vertex_position[index_tree]
476
471
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
484
475
485
476
# Insert j into tree_vertices
486
477
vertex_position[index_tree] += 1
@@ -497,12 +488,6 @@ function TreeSet(
497
488
tree_neighbor_indices[vertex_index + 1 ] += 1
498
489
end
499
490
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
506
491
end
507
492
508
493
# Compute a shifted cumulative sum of tree_edge_indices, starting from one
@@ -528,7 +513,7 @@ function TreeSet(
528
513
529
514
# Determine if each tree in the forest is a star
530
515
# 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)
532
517
533
518
# Number of edges treated
534
519
num_edges_treated = zero (T)
0 commit comments