@@ -7,17 +7,18 @@ Fill `label` with the `id` of the connected component in the undirected graph
77`g` to which it belongs. Return a vector representing the component assigned
88to each vertex. The component value is the smallest vertex ID in the component.
99
10- A `search_queue`, an empty `Vector{eltype(edgetype(g))}`, can be provided to reduce
11- allocations if `connected_components!` is intended to be called multiple times sequentially.
12- If not provided, it is automatically instantiated.
10+ ## Optional arguments
11+ - `search_queue`, an empty `Vector{eltype(edgetype(g))}`, can be provided to avoid
12+ reallocating this work array repeatedly on repeated calls of `connected_components!`.
13+ If not provided, it is automatically instantiated.
1314
14- ### Performance
15+ ## Performance
1516This algorithm is linear in the number of edges of the graph.
1617"""
1718function connected_components! (
1819 label:: AbstractVector{T} , g:: AbstractGraph{T} , search_queue:: Vector{T} = Vector {T} ()
1920) where {T}
20- isempty (search_queue) || error ( " provided `search_queue` is not empty " )
21+ empty! (search_queue)
2122 for u in vertices (g)
2223 label[u] != zero (T) && continue
2324 label[u] = u
@@ -152,13 +153,17 @@ end
152153Return the number of connected components in `g`.
153154
154155Equivalent to `length(connected_components(g))` but uses fewer allocations by not
155- materializing the component vectors explicitly. Additionally, mutated work-arrays `label`
156- and `search_queue` can be provided to reduce allocations further (see
157- [`connected_components!`](@ref)).
156+ materializing the component vectors explicitly.
157+
158+ ## Optional arguments
159+ Mutated work arrays, `label` and `search_queue` can be provided to avoid allocating these
160+ arrays repeatedly on repeated calls of `count_connected_components`.
161+ For `g :: AbstractGraph{T}`, `label` must be a zero-initialized `Vector{T}` of length
162+ `nv(g)` and `search_queue` a `Vector{T}`. See also [`connected_components!`](@ref).
158163
159164## Keyword arguments
160- - `reset_label :: Bool` (default, `false`): if `true`, `label` is reset to zero before
161- returning.
165+ - `reset_label :: Bool` (default, `false`): if `true`, `label` is reset to a zero-vector
166+ before returning.
162167
163168## Example
164169```
0 commit comments