Skip to content

Commit 21b1854

Browse files
committed
simplify count_unique
1 parent da1d31e commit 21b1854

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/connectivity.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,13 @@ 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
197199
seen = Set{T}()
198-
c = 0
199200
for l in label
200-
if l seen
201-
push!(seen, l)
202-
c += 1
203-
end
201+
l seen && push!(seen, l) # currently faster than direct `push!(seen, l)`
204202
end
205-
return c
203+
return length(seen)
206204
end
207205

208206
"""

0 commit comments

Comments
 (0)