@@ -147,15 +147,20 @@ function is_connected(g::AbstractGraph{T}) where T
147147end
148148
149149"""
150- count_connected_components( g, [label, search_queue])
150+ count_connected_components( g, [label, search_queue]; reset_label::Bool=false )
151151
152152Return the number of connected components in `g`.
153153
154154Equivalent to `length(connected_components(g))` but uses fewer allocations by not
155155materializing the component vectors explicitly. Additionally, mutated work-arrays `label`
156156and `search_queue` can be provided to reduce allocations further (see
157- [`connected_components !`](@ref)).
157+ [`_connected_components !`](@ref)).
158158
159+ ## Keyword arguments
160+ - `reset_label :: Bool` (default, `false`): if `true`, `label` is reset to zero before
161+ returning.
162+
163+ ## Example
159164```
160165julia> using Graphs
161166
@@ -174,10 +179,13 @@ julia> count_connected_components(g)
174179function count_connected_components (
175180 g:: AbstractGraph{T} ,
176181 label:: AbstractVector = zeros (T, nv (g)),
177- search_queue:: Vector{T} = Vector {T} ()
182+ search_queue:: Vector{T} = Vector {T} ();
183+ reset_label:: Bool = false
178184) where T
179- connected_components! (label, g, search_queue)
180- return count_unique (label)
185+ _connected_components! (label, g, search_queue)
186+ c = count_unique (label)
187+ reset_label && fill! (label, zero (eltype (label)))
188+ return c
181189end
182190
183191function count_unique (label:: Vector{T} ) where T
0 commit comments