@@ -10,7 +10,7 @@ using .Base: copymutable, LinearIndices, length, (:),
1010 AbstractVector, @inbounds , AbstractRange, @eval , @inline , Vector, @noinline ,
1111 AbstractMatrix, AbstractUnitRange, isless, identity, eltype, > , < , <= , >= , | , + , - , * , ! ,
1212 extrema, sub_with_overflow, add_with_overflow, oneunit, div, getindex, setindex!,
13- length, resize!, fill, Missing, require_one_based_indexing
13+ length, resize!, fill, Missing, require_one_based_indexing, keytype
1414
1515using . Base: >>> , != =
1616
@@ -174,7 +174,7 @@ midpoint(lo::Integer, hi::Integer) = midpoint(promote(lo, hi)...)
174174
175175# index of the first value of vector a that is greater than or equal to x;
176176# returns length(v)+1 if x is greater than all values in v.
177- function searchsortedfirst (v:: AbstractVector , x, lo:: T , hi:: T , o:: Ordering ) where T<: Integer
177+ function searchsortedfirst (v:: AbstractVector , x, lo:: T , hi:: T , o:: Ordering ):: keytype (v) where T<: Integer
178178 u = T (1 )
179179 lo = lo - u
180180 hi = hi + u
191191
192192# index of the last value of vector a that is less than or equal to x;
193193# returns 0 if x is less than all values of v.
194- function searchsortedlast (v:: AbstractVector , x, lo:: T , hi:: T , o:: Ordering ) where T<: Integer
194+ function searchsortedlast (v:: AbstractVector , x, lo:: T , hi:: T , o:: Ordering ):: keytype (v) where T<: Integer
195195 u = T (1 )
196196 lo = lo - u
197197 hi = hi + u
209209# returns the range of indices of v equal to x
210210# if v does not contain x, returns a 0-length range
211211# indicating the insertion point of x
212- function searchsorted (v:: AbstractVector , x, ilo:: T , ihi:: T , o:: Ordering ) where T<: Integer
212+ function searchsorted (v:: AbstractVector , x, ilo:: T , ihi:: T , o:: Ordering ):: UnitRange{keytype(v)} where T<: Integer
213213 u = T (1 )
214214 lo = ilo - u
215215 hi = ihi + u
@@ -228,7 +228,7 @@ function searchsorted(v::AbstractVector, x, ilo::T, ihi::T, o::Ordering) where T
228228 return (lo + 1 ) : (hi - 1 )
229229end
230230
231- function searchsortedlast (a:: AbstractRange{<:Real} , x:: Real , o:: DirectOrdering )
231+ function searchsortedlast (a:: AbstractRange{<:Real} , x:: Real , o:: DirectOrdering ):: keytype (a)
232232 require_one_based_indexing (a)
233233 if step (a) == 0
234234 lt (o, x, first (a)) ? 0 : length (a)
@@ -238,7 +238,7 @@ function searchsortedlast(a::AbstractRange{<:Real}, x::Real, o::DirectOrdering)
238238 end
239239end
240240
241- function searchsortedfirst (a:: AbstractRange{<:Real} , x:: Real , o:: DirectOrdering )
241+ function searchsortedfirst (a:: AbstractRange{<:Real} , x:: Real , o:: DirectOrdering ):: keytype (a)
242242 require_one_based_indexing (a)
243243 if step (a) == 0
244244 lt (o, first (a), x) ? length (a) + 1 : 1
@@ -248,7 +248,7 @@ function searchsortedfirst(a::AbstractRange{<:Real}, x::Real, o::DirectOrdering)
248248 end
249249end
250250
251- function searchsortedlast (a:: AbstractRange{<:Integer} , x:: Real , o:: DirectOrdering )
251+ function searchsortedlast (a:: AbstractRange{<:Integer} , x:: Real , o:: DirectOrdering ):: keytype (a)
252252 require_one_based_indexing (a)
253253 h = step (a)
254254 if h == 0
@@ -270,7 +270,7 @@ function searchsortedlast(a::AbstractRange{<:Integer}, x::Real, o::DirectOrderin
270270 end
271271end
272272
273- function searchsortedfirst (a:: AbstractRange{<:Integer} , x:: Real , o:: DirectOrdering )
273+ function searchsortedfirst (a:: AbstractRange{<:Integer} , x:: Real , o:: DirectOrdering ):: keytype (a)
274274 require_one_based_indexing (a)
275275 h = step (a)
276276 if h == 0
@@ -285,14 +285,14 @@ function searchsortedfirst(a::AbstractRange{<:Integer}, x::Real, o::DirectOrderi
285285 lastindex (a) + 1
286286 else
287287 if o isa ForwardOrdering
288- - fld (floor (Integer, - x) + first (a), h) + 1
288+ - fld (floor (Integer, - x) + Signed ( first (a) ), h) + 1
289289 else
290- - fld (ceil (Integer, - x) + first (a), h) + 1
290+ - fld (ceil (Integer, - x) + Signed ( first (a) ), h) + 1
291291 end
292292 end
293293end
294294
295- function searchsortedfirst (a:: AbstractRange{<:Integer} , x:: Unsigned , o:: DirectOrdering )
295+ function searchsortedfirst (a:: AbstractRange{<:Integer} , x:: Unsigned , o:: DirectOrdering ):: keytype (a)
296296 require_one_based_indexing (a)
297297 if lt (o, first (a), x)
298298 if step (a) == 0
@@ -305,7 +305,7 @@ function searchsortedfirst(a::AbstractRange{<:Integer}, x::Unsigned, o::DirectOr
305305 end
306306end
307307
308- function searchsortedlast (a:: AbstractRange{<:Integer} , x:: Unsigned , o:: DirectOrdering )
308+ function searchsortedlast (a:: AbstractRange{<:Integer} , x:: Unsigned , o:: DirectOrdering ):: keytype (a)
309309 require_one_based_indexing (a)
310310 if lt (o, x, first (a))
311311 0
0 commit comments