| 345 | |
| 346 | template <arg_t arg> |
| 347 | static inline typename binsearch_t<arg>::function_type |
| 348 | _get_binsearch_func(PyArray_Descr *dtype, NPY_SEARCHSIDE side) |
| 349 | { |
| 350 | using binsearch = binsearch_t<arg>; |
| 351 | npy_intp nfuncs = binsearch::map.size(); |
| 352 | npy_intp min_idx = 0; |
| 353 | npy_intp max_idx = nfuncs; |
| 354 | int type = dtype->type_num; |
| 355 | |
| 356 | if ((int)side >= (int)NPY_NSEARCHSIDES) { |
| 357 | return NULL; |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * It seems only fair that a binary search function be searched for |
| 362 | * using a binary search... |
| 363 | */ |
| 364 | while (min_idx < max_idx) { |
| 365 | npy_intp mid_idx = min_idx + ((max_idx - min_idx) >> 1); |
| 366 | |
| 367 | if (binsearch::map[mid_idx].typenum < type) { |
| 368 | min_idx = mid_idx + 1; |
| 369 | } |
| 370 | else { |
| 371 | max_idx = mid_idx; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | if (min_idx < nfuncs && binsearch::map[min_idx].typenum == type) { |
| 376 | return binsearch::map[min_idx].binsearch[side]; |
| 377 | } |
| 378 | |
| 379 | if (dtype->f->compare) { |
| 380 | return binsearch::npy_map[side]; |
| 381 | } |
| 382 | |
| 383 | return NULL; |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | ***************************************************************************** |