Skip to content

Commit ead687e

Browse files
committed
improve comments for count_unique
1 parent 21b1854 commit ead687e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/connectivity.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,14 @@ function count_connected_components(
194194
end
195195

196196
function count_unique(label::Vector{T}) where {T}
197-
# effectively does `length(Set(label))` but slightly faster since `Set(label)`
198-
# sizehints too aggressively for the use case of having relatively few unique elements
197+
# effectively does `length(Set(label))` but faster, since `Set(label)` sizehints
198+
# aggressively and assumes that most elements of `label` will be unique, which very
199+
# rarely will be the case for caller `count_connected_components!`
199200
seen = Set{T}()
200201
for l in label
201-
l seen && push!(seen, l) # currently faster than direct `push!(seen, l)`
202+
# faster than direct `push!(seen, l)` when `label` has few unique elements relative
203+
# to `length(label)`
204+
l seen && push!(seen, l)
202205
end
203206
return length(seen)
204207
end

0 commit comments

Comments
 (0)