Skip to content

Commit 68e0398

Browse files
committedMay 22, 2013
make unique preserve order. fixes #3174
1 parent 95efbff commit 68e0398

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed
 

‎base/set.jl

+11-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,17 @@ function <=(l::Set, r::Set)
9494
return true
9595
end
9696

97-
unique(C) = collect(union!(Set{eltype(C)}(), C))
97+
function unique(C)
98+
out = Array(eltype(C),0)
99+
seen = Set{eltype(C)}()
100+
for x in C
101+
if !contains(seen, x)
102+
add!(seen, x)
103+
push!(out, x)
104+
end
105+
end
106+
out
107+
end
98108

99109
function filter!(f::Function, s::Set)
100110
for x in s

0 commit comments

Comments
 (0)
Please sign in to comment.