From 678e57098e8a2377cb008db7358de529fb9fe3e4 Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Tue, 5 Mar 2013 19:45:50 -0800 Subject: [PATCH 1/2] Fix findnext on BitArrays --- base/bitarray.jl | 22 ++++++++++++++++++++-- test/bitarray.jl | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index d0d33b17b921d..5ffbf355eb4dc 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1477,7 +1477,16 @@ end # returns the index of the next non-zero element, or 0 if all zeros function findnext(B::BitArray, start::Integer) Bc = B.chunks - for i = div(start-1,64)+1:length(Bc) + + chunk_start = div(start-1, 64)+1 + within_chunk_start = start-1-chunk_start*64 + mask = _msk64-((1<> i) == i+1 + @test Base.findfirstnot(~(b1 >> i)) == i+1 +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 + end +end + b1 = randbool(n1, n2) @check_bit_operation findn_nzs (Vector{Int}, Vector{Int}, BitArray) (b1,) From 86df5a6529053b73db875ab2dace8699a504e25f Mon Sep 17 00:00:00 2001 From: Kevin Squire Date: Wed, 6 Mar 2013 00:10:31 -0800 Subject: [PATCH 2/2] Update findnext to use helper macros. --- base/bitarray.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 5ffbf355eb4dc..129cb67cca2be 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1478,9 +1478,9 @@ end function findnext(B::BitArray, start::Integer) Bc = B.chunks - chunk_start = div(start-1, 64)+1 - within_chunk_start = start-1-chunk_start*64 - mask = _msk64-((1<