Skip to content

Commit

Permalink
Put unique loop in another function
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloferz committed Feb 1, 2017
1 parent 20750bf commit 06eac24
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,28 @@ function unique(itr)
x, i = next(itr, i)
if !isleaftype(T)
T = typeof(x)
out = Vector{T}()
seen = Set{T}()
return _unique(itr, Vector{T}(), Set{T}(), x, i)
end
push!(seen, x)
push!(out, x)
if !done(itr, i)
x, i = next(itr, i)
end
return unique(itr, out, seen, x, i)
end

@inline unique(itr, out, seen, x, i) = _unique(itr, out, seen, x, i)
function _unique{T}(itr, out::Vector{T}, seen, x, i)
if !in(x, seen)
push!(seen, x)
push!(out, x)
end
while !done(itr, i)
x, i = next(itr, i)
S = typeof(x)
if !(S === T || S <: T)
T = typejoin(S, T)
seen = convert(Set{T}, seen)
out = convert(Vector{T}, out)
R = typejoin(S, T)
return _unique(itr, convert(Vector{R}, out), convert(Set{R}, seen), x, i)
end
if !in(x, seen)
push!(seen, x)
Expand Down

0 comments on commit 06eac24

Please sign in to comment.