From 5c7df3d2ed73a3f54caeaa3c5c5d45b5a47e0649 Mon Sep 17 00:00:00 2001 From: Alexis Montoison <35051714+amontoison@users.noreply.github.com> Date: Wed, 12 Feb 2025 11:59:06 -0600 Subject: [PATCH 1/3] Update disjoint_set.jl Improve `sizehint!(DisjointSets)` such that we preallocate the vectors needed by the internal `IntDisjointSets`. --- src/disjoint_set.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/disjoint_set.jl b/src/disjoint_set.jl index 364645472..e41ed2341 100644 --- a/src/disjoint_set.jl +++ b/src/disjoint_set.jl @@ -182,6 +182,8 @@ Base.empty(s::DisjointSet{T}, ::Type{U}=T) where {T,U} = DisjointSet{U}() function Base.sizehint!(s::DisjointSet, n::Integer) sizehint!(s.intmap, n) sizehint!(s.revmap, n) + sizehint!(s.internal.parents, n) + sizehint!(s.internal.ranks, n) return s end From 07d5bb120c36506cf02c1bdffacc2555db7101a5 Mon Sep 17 00:00:00 2001 From: Alexis Montoison <35051714+amontoison@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:44:06 -0600 Subject: [PATCH 2/3] Update src/disjoint_set.jl Co-authored-by: Frames White --- src/disjoint_set.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/disjoint_set.jl b/src/disjoint_set.jl index e41ed2341..2a27795e8 100644 --- a/src/disjoint_set.jl +++ b/src/disjoint_set.jl @@ -182,8 +182,7 @@ Base.empty(s::DisjointSet{T}, ::Type{U}=T) where {T,U} = DisjointSet{U}() function Base.sizehint!(s::DisjointSet, n::Integer) sizehint!(s.intmap, n) sizehint!(s.revmap, n) - sizehint!(s.internal.parents, n) - sizehint!(s.internal.ranks, n) + sizehint!(s.internal, n) return s end From 4dd340ce798d3f499a938bb4abefedc7bb2c813b Mon Sep 17 00:00:00 2001 From: Alexis Montoison <35051714+amontoison@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:48:13 -0600 Subject: [PATCH 3/3] Update disjoint_set.jl --- src/disjoint_set.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/disjoint_set.jl b/src/disjoint_set.jl index 2a27795e8..d4a396d7a 100644 --- a/src/disjoint_set.jl +++ b/src/disjoint_set.jl @@ -32,6 +32,11 @@ end IntDisjointSet(n::T) where {T<:Integer} = IntDisjointSet{T}(collect(Base.OneTo(n)), zeros(T, n), n) IntDisjointSet{T}(n::Integer) where {T<:Integer} = IntDisjointSet{T}(collect(Base.OneTo(T(n))), zeros(T, T(n)), T(n)) Base.length(s::IntDisjointSet) = length(s.parents) +function Base.sizehint!(s::IntDisjointSet, n::Integer) + sizehint!(s.parents, n) + sizehint!(s.ranks, n) + return s +end """ num_groups(s::IntDisjointSet)