Skip to content

Commit

Permalink
Fix pop! with negative numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman committed Jul 22, 2015
1 parent 3126831 commit be2c6ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/intset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ function pop!(s::IntSet, n::Integer, deflt)
return deflt
end
end
if n < 0
return deflt
end
mask = UInt32(1)<<(n&31)
idx = n>>5 + 1
b = s.bits[idx]
Expand Down
1 change: 1 addition & 0 deletions test/intset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ s = IntSet([0,1,10,20,200,300,1000,10000,10002])
@test first(s) == 0
@test length(s) == 9
@test pop!(s) == 10002
@test_throws KeyError pop!(s, -1)
@test length(s) == 8
@test shift!(s) == 0
@test length(s) == 7
Expand Down

0 comments on commit be2c6ea

Please sign in to comment.