Skip to content

Commit

Permalink
Fix #8025 (findfirst(::Function,::BitArray))
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobaldassi committed Aug 17, 2014
1 parent 4ba73cf commit 3a8da6a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
12 changes: 6 additions & 6 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1280,20 +1280,20 @@ function findnextnot(B::BitArray, start::Integer)
within_chunk_start = @_mod64(start-1)
mask = ~(_msk64 << within_chunk_start)

@inbounds begin
@inbounds if chunk_start < l
if Bc[chunk_start] | mask != _msk64
return (chunk_start-1) << 6 + trailing_ones(Bc[chunk_start] | mask) + 1
end

for i = chunk_start+1:l-1
if Bc[i] != _msk64
return (i-1) << 6 + trailing_ones(Bc[i]) + 1
end
end
ce = Bc[end]
end
if ce != @_msk_end length(B)
return (l-1) << 6 + trailing_ones(ce) + 1
if Bc[l] != @_msk_end length(B)
return (l-1) << 6 + trailing_ones(Bc[l]) + 1
end
elseif Bc[l] | mask != @_msk_end length(B)
return (l-1) << 6 + trailing_ones(Bc[l] | mask) + 1
end
return 0
end
Expand Down
29 changes: 14 additions & 15 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -809,23 +809,22 @@ timesofar("datamove")

## countnz & find ##

b1 = randbool(v1)
@check_bit_operation countnz(b1) Int
for m = 0:v1, b1 in {randbool(m), trues(m), falses(m)}
@check_bit_operation countnz(b1) Int

@check_bit_operation findfirst(b1) Int
@check_bit_operation findfirst(trues(v1)) Int
@check_bit_operation findfirst(falses(v1)) Int
@check_bit_operation findfirst(b1) Int

@check_bit_operation findfirst(b1, true) Int
@check_bit_operation findfirst(b1, false) Int
@check_bit_operation findfirst(b1, 3) Int
@check_bit_operation findfirst(b1, true) Int
@check_bit_operation findfirst(b1, false) Int
@check_bit_operation findfirst(b1, 3) Int

@check_bit_operation findfirst(x->x, b1) Int
@check_bit_operation findfirst(x->!x, b1) Int
@check_bit_operation findfirst(x->true, b1) Int
@check_bit_operation findfirst(x->false, b1) Int
@check_bit_operation findfirst(x->x, b1) Int
@check_bit_operation findfirst(x->!x, b1) Int
@check_bit_operation findfirst(x->true, b1) Int
@check_bit_operation findfirst(x->false, b1) Int

@check_bit_operation find(b1) Vector{Int}
@check_bit_operation find(b1) Vector{Int}
end

b1 = trues(v1)
for i = 0:v1-1
Expand All @@ -836,8 +835,8 @@ end
for i = 3:v1-1
for j = 2:i
submask = b1 << (v1-j+1)
@test findnext((b1 >> i) | submask,j) == i+1
@test Base.findnextnot((~(b1 >> i)) $ submask,j) == i+1
@test findnext((b1 >> i) | submask, j) == i+1
@test Base.findnextnot((~(b1 >> i)) $ submask, j) == i+1
end
end

Expand Down

0 comments on commit 3a8da6a

Please sign in to comment.