Calico
binary_search.h File Reference

Binary search. More...

Functions

static int cal_binary_search (const void *key, const void *ptr, size_t count, size_t size, int(*cmp)(void *, const void *, const void *), void *cmp_ctx, size_t *pos_out)
 Perform a binary search on a sorted array pointed by ptr. More...
 

Detailed Description

Binary search.

Function Documentation

static int cal_binary_search ( const void *  key,
const void *  ptr,
size_t  count,
size_t  size,
int(*)(void *, const void *, const void *)  cmp,
void *  cmp_ctx,
size_t *  pos_out 
)
inlinestatic

Perform a binary search on a sorted array pointed by ptr.

If the search was successful, 1 is returned and *pos_out is set to the index of the element that compares equal to key. Otherwise, 0 is returned and *pos_out is set to the index of the smallest element greater than key. pos_out is optional and can be null.