-
-
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
Feature Request: in
sorted array
#37442
Comments
Without giving it much thought, this seems like it might be better (more orthogonally) achieved with a wrapper type to annotate that an struct Sorted{T}
_::T
end
function Base.in(x, v::Sorted)
r = searchsorted(a._, x)
return length(r) > 0
end Then you can even use infix
|
I think I would prefer an independent function to be consistent with the functions I'm working on it but I have a few issues with |
I understand the desire to be consistent. In my opinion, the situation with There are three ideas: search (or find), sorted/unsorted, first/last/all. So really it's If I'm not mistaken (here is a monte carlo proof: using Test
for _ = 1:10000
a = cumsum(rand(0:1, 10))
q = rand(1:10)
r = searchsorted(a, q)
fr = searchsortedfirst(a, q)
lr = searchsortedlast(a, q)
@test first(r) === fr
@test last(r) === lr
end )
|
Imho the solution should be found in a better naming and not a new structure, that would had an extra layer that should be avoided. What does However, |
Duplicate of #24883 |
I can see that my comments have duplicated things that I now see have been written before, but I don't see the feature request as a duplicate. |
Sorry if I misunderstood something, to me the feature request was not a duplicate. |
Their is a "find" function in sorted arrays:
searchsorted
:julia/base/sort.jl
Lines 212 to 229 in eb2a801
Is that a possible option to add
insorted
that does the same asin
but knowing that the collection is sorted?The text was updated successfully, but these errors were encountered: