Skip to content

Commit

Permalink
Refactor IntSets
Browse files Browse the repository at this point in the history
* Complete deprecation of stored zeros; IntSets now only support integers in the range `1:typemax(Int)`
* Complete deprecation of `complement`; removes all support for inverted IntSets
* Refactor internals to rely on a BitVector, allowing the use of highly optimized `map` methods. `IntSet` is now immutable. This significantly improves performance across varying [densities](http://imgur.com/a/uqv8A) and [sizes](http://imgur.com/a/iEgcr). These are compared against a modified Base with deprecation warnings removed for a fairer comparison. Testing code [available here](https://github.com/mbauman/IntSets.jl/tree/b50a7c97abbe9786e33221f723e107e266f31fe4/test).
* Add more tests and organize into testsets.
* Improve hashing; `hash(IntSet([1]))` is now distinct from `hash(IntSet([65]))`

This is a continuation of #10065. Now that complements are fully removed, making IntSet immutable solves the performance issue. I am keeping the name the same within this PR as it vastly simplifies comparisons between the two implementations; the name can later be changed to `IndexSet` if still desired. The naming story is now a bit more complicated since we support offset indices, but a future change could perhaps allow wrapping any `AbstractVector{Bool}` and base the supported `Int`s on those indices. Very few methods depend upon BitArray internals.
  • Loading branch information
mbauman committed Feb 4, 2017
1 parent e480969 commit 0be5cda
Show file tree
Hide file tree
Showing 6 changed files with 451 additions and 418 deletions.
14 changes: 14 additions & 0 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,20 @@ end
return B
end

indexoffset(i) = first(i)-1
indexoffset(::Colon) = 0

@inline function setindex!(B::BitArray, x, J0::Union{Colon,UnitRange{Int}})
I0 = to_indices(B, (J0,))[1]
@boundscheck checkbounds(B, I0)
y = Bool(x)
l0 = length(I0)
l0 == 0 && return B
f0 = indexoffset(I0)+1
fill_chunks!(B.chunks, y, f0, l0)
return B
end

# logical indexing

# When indexing with a BitArray, we can operate whole chunks at a time for a ~100x gain
Expand Down
1 change: 1 addition & 0 deletions base/coreimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ end
include("reduce.jl")

## core structures
include("bitarray.jl")
include("intset.jl")
include("associative.jl")

Expand Down
4 changes: 2 additions & 2 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2586,8 +2586,8 @@ function typeinf_frame(frame)
local pc´::Int = pc + 1 # next program-counter (after executing instruction)
if pc == frame.pc´´
# need to update pc´´ to point at the new lowest instruction in W
min_pc = next(W, Int64(pc) + 1)[1]
if min_pc >= W.limit
min_pc = next(W, Int64(pc))[2]
if done(W, min_pc)
frame.pc´´ = max(min_pc, n + 1)
else
frame.pc´´ = min_pc
Expand Down
Loading

0 comments on commit 0be5cda

Please sign in to comment.