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 7, 2017
1 parent b8d81c7 commit 432478d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,28 @@ function unique(itr)
end
x, i = next(itr, i)
if !isleaftype(T)
T = typeof(x)
out = Vector{T}()
seen = Set{T}()
S = typeof(x)
return _unique_from(itr, S[x], Set{S}((x,)), i)
end
push!(seen, x)
push!(out, x)
return unique_from(itr, out, seen, i)
end

_unique_from(itr, out, seen, i) = unique_from(itr, out, seen, i)
@inline function unique_from{T}(itr, out::Vector{T}, seen, i)
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)
seenR = convert(Set{R}, seen)
outR = convert(Vector{R}, out)
if !in(x, seenR)
push!(seenR, x)
push!(outR, x)
end
return _unique_from(itr, outR, seenR, i)
end
if !in(x, seen)
push!(seen, x)
Expand Down

0 comments on commit 432478d

Please sign in to comment.