#include "vec.h" type_len vec_bsrch(type_len typesize, vec_type const* vec, void const* d, int (*compar)(void const*, void const*), type_bool last, type_len left) { type_len l, r, i; int ret; l=left, 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 (last) l=i+1; else r=i; } return l-left; }