#include "vec.h" size_t vec_bsrch(size_t typesize, vec_type const* vec, void const* d, int (*compar)(void const*, void const*), type_bool first) { size_t l, r, i; int ret; l=0, r=vec->len/typesize; while (l!=r) { i=(l+r)/2; ret=compar(vec->s+i*typesize, d); if (ret<0) l=i+1; else if (ret>0) r=i; else if (first) r=i; else l=i+1; } return l; }