From 0ce6e4272ec606154d3d9cf805fcfb189b464cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 9 Jan 2026 13:41:46 +0100 Subject: [PATCH 1/5] Document fields of TreeSet --- src/coloring.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/coloring.jl b/src/coloring.jl index cf3d8f79..557937c2 100644 --- a/src/coloring.jl +++ b/src/coloring.jl @@ -422,9 +422,18 @@ Encode a set of 2-colored trees resulting from the [`acyclic_coloring`](@ref) al $TYPEDFIELDS """ struct TreeSet{T} + """ + contains the reverse breadth first (BFS) traversal order for each tree in the forest. + More precisely, given an edge `(u, v)` of index `i`, + `reverse_bfs_order[i]` is either `(u, v)` or `(v, u)`. + The first node of the tuple is the leaf in the reverse BFS order. + """ reverse_bfs_orders::Vector{Tuple{T,T}} + "For a tree index `1 <= k <= nt`, `is_star[k]` indicates whether the `k`th three is a star." is_star::Vector{Bool} + "`tree_edge_indices[1]` is one and `tree_edge_indices[k+1] - tree_edge_indices[k]` is the number of edges in the `k`th tree" tree_edge_indices::Vector{T} + "numbers of 2-colored trees for which trees sharing the same 2 colors have disjoint vertices" nt::T end @@ -432,6 +441,7 @@ function TreeSet( g::AdjacencyGraph{T}, forest::Forest{T}, buffer::AbstractVector{T}, + # The value of `reverse_bfs_orders` is ignored, we just reuse its memory reverse_bfs_orders::Vector{Tuple{T,T}}, ne::Integer, ) where {T} @@ -566,7 +576,6 @@ function TreeSet( # Number of edges treated num_edges_treated = zero(T) - # reverse_bfs_orders contains the reverse breadth first (BFS) traversal order for each tree in the forest for k in 1:nt # Initialize the queue to store the leaves queue_start = 1 From 8b377bed685cb8c0b28d9d8f80ae1a3b1a1da0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 10 Jan 2026 09:41:23 +0100 Subject: [PATCH 2/5] Update src/coloring.jl Co-authored-by: Alexis Montoison <35051714+amontoison@users.noreply.github.com> --- src/coloring.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coloring.jl b/src/coloring.jl index 557937c2..44e6baf9 100644 --- a/src/coloring.jl +++ b/src/coloring.jl @@ -441,7 +441,7 @@ function TreeSet( g::AdjacencyGraph{T}, forest::Forest{T}, buffer::AbstractVector{T}, - # The value of `reverse_bfs_orders` is ignored, we just reuse its memory + # The value of `reverse_bfs_orders` is ignored, we just provide the storage for it (or reuse memory allocated during acyclic coloring) reverse_bfs_orders::Vector{Tuple{T,T}}, ne::Integer, ) where {T} From d25581bc70c296032aae5dd46b4d8609f4dd239c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 10 Jan 2026 09:54:26 +0100 Subject: [PATCH 3/5] Update src/coloring.jl --- src/coloring.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/coloring.jl b/src/coloring.jl index 44e6baf9..ad315048 100644 --- a/src/coloring.jl +++ b/src/coloring.jl @@ -431,7 +431,10 @@ struct TreeSet{T} reverse_bfs_orders::Vector{Tuple{T,T}} "For a tree index `1 <= k <= nt`, `is_star[k]` indicates whether the `k`th three is a star." is_star::Vector{Bool} - "`tree_edge_indices[1]` is one and `tree_edge_indices[k+1] - tree_edge_indices[k]` is the number of edges in the `k`th tree" + """ + `tree_edge_indices[1]` is one and `tree_edge_indices[k+1] - tree_edge_indices[k]` is the number of edges in the `k`th tree. + One can think of it as a kind of fused vector of offsets (similar to the `colptr` field of `SparseMatrixCSC`) of all trees together. + """ tree_edge_indices::Vector{T} "numbers of 2-colored trees for which trees sharing the same 2 colors have disjoint vertices" nt::T From 4cd18b575fe318d32ee83f9e9f502982fea688ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 19 Jan 2026 12:31:20 +0100 Subject: [PATCH 4/5] Address comments --- src/coloring.jl | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/coloring.jl b/src/coloring.jl index ad315048..685895b9 100644 --- a/src/coloring.jl +++ b/src/coloring.jl @@ -424,9 +424,12 @@ $TYPEDFIELDS struct TreeSet{T} """ contains the reverse breadth first (BFS) traversal order for each tree in the forest. - More precisely, given an edge `(u, v)` of index `i`, - `reverse_bfs_order[i]` is either `(u, v)` or `(v, u)`. - The first node of the tuple is the leaf in the reverse BFS order. + For a tree index `1 <= k <= nt`, the list + `list = reverse_bfs_order[tree_edge_indices[k]:(tree_edge_indices[k+1]-1)]` is a list of edges + `list[i] = (leaf, inner)` of the `k`th tree such that `leaf` is a leaf of the tree containing + the edges `list[i:end]`. + From an other point of view, `reverse(list)` contains the edges in the order of a breadth first + (BFS) traversal order of the `k`th tree starting from a depth-minimizing root. """ reverse_bfs_orders::Vector{Tuple{T,T}} "For a tree index `1 <= k <= nt`, `is_star[k]` indicates whether the `k`th three is a star." @@ -436,7 +439,7 @@ struct TreeSet{T} One can think of it as a kind of fused vector of offsets (similar to the `colptr` field of `SparseMatrixCSC`) of all trees together. """ tree_edge_indices::Vector{T} - "numbers of 2-colored trees for which trees sharing the same 2 colors have disjoint vertices" + "numbers of 2-colored trees for which trees sharing the same 2 colors have disjoint edges" nt::T end @@ -579,6 +582,15 @@ function TreeSet( # Number of edges treated num_edges_treated = zero(T) + # The `rank` of the `k`th tree encoded in `forest` does not correspond + # to the depth of the tree rooted as the root encoded in `forest` because + # `forest.parents[u] = v` only needs a path to exists from `u` to `v` but + # there may not be an edge `(u, v)`. + # We also want a root `r` that minimizes the depth of the tree rooted at + # `r`. To achieve this, we start from each leaf and remove the corresponding + # edges. We then look at all leaves of the corresponding graphs and repeat + # the process until there is only one vertex left. This vertex will then be + # a depth-minimizing root. for k in 1:nt # Initialize the queue to store the leaves queue_start = 1 From 20ab1177b40794d32629eb042cd7a6848f1a10de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 19 Jan 2026 12:33:35 +0100 Subject: [PATCH 5/5] Fix --- src/coloring.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coloring.jl b/src/coloring.jl index 685895b9..84007d56 100644 --- a/src/coloring.jl +++ b/src/coloring.jl @@ -423,7 +423,6 @@ $TYPEDFIELDS """ struct TreeSet{T} """ - contains the reverse breadth first (BFS) traversal order for each tree in the forest. For a tree index `1 <= k <= nt`, the list `list = reverse_bfs_order[tree_edge_indices[k]:(tree_edge_indices[k+1]-1)]` is a list of edges `list[i] = (leaf, inner)` of the `k`th tree such that `leaf` is a leaf of the tree containing