Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/PersistentSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ Base.@deprecate(PersistentSet(x1::T, x2::T, xs::T...) where {T},
Base.hash(s::PersistentSet,h::UInt) =
hash(s.dict, h+(UInt(0xf7dca1a5fd7090be)))

Base.conj(s::PersistentSet{T}, val) where {T} =
push(s::PersistentSet{T}, val) where {T} =
PersistentSet{T}(assoc(s.dict, val, nothing))

push(s::PersistentSet, val) = conj(s, val)

disj(s::PersistentSet{T}, val) where {T} =
PersistentSet{T}(dissoc(s.dict, val))

Expand Down Expand Up @@ -52,7 +50,7 @@ Base.isempty(s::PersistentSet) = length(s.dict) == 0

function _union(s::PersistentSet, xs)
for x in xs
s = conj(s, x)
s = push(s, x)
end
s
end
Expand Down
8 changes: 4 additions & 4 deletions test/PersistentSetTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const PS = PersistentSet
@test PS{String}() == PS{Int}()
end

@testset "conj" begin
@test conj(PS([1, 2, 3]), 4) == PS([1, 2, 3, 4])
@test conj(PS([1, 2, 3]), 1) == PS([1, 2, 3])
@test conj(PS([1, 2, 3]), 4) == PS([4, 3, 2, 1])
@testset "push" begin
@test push(PS([1, 2, 3]), 4) == PS([1, 2, 3, 4])
@test push(PS([1, 2, 3]), 1) == PS([1, 2, 3])
@test push(PS([1, 2, 3]), 4) == PS([4, 3, 2, 1])
end

@testset "disj" begin
Expand Down