-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make searchsorted*/findnext/findprev return values of keytype #32978
Changes from 2 commits
e392400
5558113
831f607
2f5ef4a
d820a59
f55346e
d3aa626
ee5c898
c666306
61abe1d
57dd806
1e4db52
62d3586
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1385,7 +1385,7 @@ end | |
function findnext(B::BitArray, start::Integer) | ||
start > 0 || throw(BoundsError(B, start)) | ||
start > length(B) && return nothing | ||
unsafe_bitfindnext(B.chunks, start) | ||
unsafe_bitfindnext(B.chunks, Int(start)) | ||
end | ||
|
||
#findfirst(B::BitArray) = findnext(B, 1) ## defined in array.jl | ||
|
@@ -1399,8 +1399,9 @@ function findnextnot(B::BitArray, start::Integer) | |
l = length(Bc) | ||
l == 0 && return nothing | ||
|
||
chunk_start = _div64(start-1)+1 | ||
within_chunk_start = _mod64(start-1) | ||
st = Int(start) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As an aside, note that for this kind of thing, there is no problem writing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, then I will change it. |
||
chunk_start = _div64(st-1)+1 | ||
within_chunk_start = _mod64(st-1) | ||
mask = ~(_msk64 << within_chunk_start) | ||
|
||
@inbounds if chunk_start < l | ||
|
@@ -1468,7 +1469,7 @@ end | |
function findprev(B::BitArray, start::Integer) | ||
start > 0 || return nothing | ||
start > length(B) && throw(BoundsError(B, start)) | ||
unsafe_bitfindprev(B.chunks, start) | ||
unsafe_bitfindprev(B.chunks, Int(start)) | ||
end | ||
|
||
function findprevnot(B::BitArray, start::Integer) | ||
|
@@ -1477,8 +1478,9 @@ function findprevnot(B::BitArray, start::Integer) | |
|
||
Bc = B.chunks | ||
|
||
chunk_start = _div64(start-1)+1 | ||
mask = ~_msk_end(start) | ||
st = Int(start) | ||
chunk_start = _div64(st-1)+1 | ||
mask = ~_msk_end(st) | ||
|
||
@inbounds begin | ||
if Bc[chunk_start] | mask != _msk64 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ function findnext(testf::Function, s::AbstractString, i::Integer) | |
@inbounds i == z || isvalid(s, i) || string_index_err(s, i) | ||
for (j, d) in pairs(SubString(s, i)) | ||
if testf(d) | ||
return i + j - 1 | ||
return Int(i + j - 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a conversion is needed somewhere in this function, my personal preference would favor converting at the begining ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I have changed it. |
||
end | ||
end | ||
return nothing | ||
|
@@ -272,7 +272,7 @@ julia> findnext("Lang", "JuliaLang", 2) | |
6:9 | ||
``` | ||
""" | ||
findnext(t::AbstractString, s::AbstractString, i::Integer) = _search(s, t, i) | ||
findnext(t::AbstractString, s::AbstractString, i::Integer) = _search(s, t, Int(i)) | ||
|
||
""" | ||
findnext(ch::AbstractChar, string::AbstractString, start::Integer) | ||
|
@@ -484,7 +484,7 @@ julia> findprev("Julia", "JuliaLang", 6) | |
1:5 | ||
``` | ||
""" | ||
findprev(t::AbstractString, s::AbstractString, i::Integer) = _rsearch(s, t, i) | ||
findprev(t::AbstractString, s::AbstractString, i::Integer) = _rsearch(s, t, Int(i)) | ||
|
||
""" | ||
findprev(ch::AbstractChar, string::AbstractString, start::Integer) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsafe_bitfindnext
(andprev
, too) accepts astart::Integer
. I was about to make a comment that we should just move this there and/or restrict its signature, but then I realized it's also used byBitSet
.BitSet
demands anInt64
result, whereas its use forBitArray
demands anInt
result. So this seems like the right way to go about it. 👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it changed, but my impression is that
BitSet
callsunsafe_bitfindnext
by feeding it anInt
, not anInt64
, so I would also favor restrictingunsafe_bitfindnext
toInt
input, as this is an internal function. But the PR is also fine as is!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now restricted
unsafe_bitfindnext
toInt
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sorry for the nitpick, but please change also
unsafe_bitfindprev
accordingly too :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was fast!