File tree Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Expand file tree Collapse file tree 2 files changed +10
-15
lines changed Original file line number Diff line number Diff line change @@ -232,26 +232,20 @@ impl<T: ArrayValue> Array<T> {
232
232
if haystack. rank ( ) - needle. rank ( ) == 1 {
233
233
if haystack. meta . is_sorted_up ( ) {
234
234
// Binary search
235
- if haystack. row_count ( ) == 0 {
236
- return Ok ( default. into ( ) ) ;
237
- }
238
235
let needle_slice = ArrayCmpSlice ( needle. data . as_slice ( ) ) ;
239
236
let mut l = 0 ;
240
- let mut r = haystack. row_count ( ) . saturating_sub ( 1 ) ;
241
- let mut res = None ;
242
- while l <= r {
237
+ let mut r = haystack. row_count ( ) ;
238
+ while l < r {
243
239
let mid = l + ( r - l) / 2 ;
244
- match ArrayCmpSlice ( haystack. row_slice ( mid) ) . cmp ( & needle_slice) {
245
- Ordering :: Equal => {
246
- res = Some ( mid) ;
247
- break ;
248
- }
249
- Ordering :: Less => l = mid + 1 ,
250
- Ordering :: Greater if mid == 0 => break ,
251
- Ordering :: Greater => r = mid - 1 ,
240
+ if ArrayCmpSlice ( haystack. row_slice ( mid) ) < needle_slice {
241
+ l = mid + 1 ;
242
+ } else {
243
+ r = mid;
252
244
}
253
245
}
254
- ( res. map ( |i| i as f64 ) . unwrap_or ( default) ) . into ( )
246
+ let found = l < haystack. row_count ( )
247
+ && ArrayCmpSlice ( haystack. row_slice ( l) ) == needle_slice;
248
+ if found { l as f64 } else { default } . into ( )
255
249
} else {
256
250
// Linear search
257
251
( haystack
Original file line number Diff line number Diff line change @@ -340,6 +340,7 @@ F ← ⬚10(/+◌1⊞(ׯ))
340
340
⍤⤙≍ [1 1 0] ⧈≠ [1 2 3 3]
341
341
◌≡(⍆∘) ≡⊏⊙¤ ⊸(≡⍏ gen⊙0 ⊟100⧻) °△21_2
342
342
⍤⤙≍ 1 /↥ [NaN 1]
343
+ ⍤⤙≍0 ⊗1 ⍆[1 1 1 1 1 1 1 1]
343
344
344
345
# Range start
345
346
⍤⤙≍ [1 2 3 4 5] ⇡₁5
You can’t perform that action at this time.
0 commit comments