提交 977679f2 编写于 作者: B Behdad Esfahbod

Add hb_bsearch_r()

上级 0712e915
......@@ -28,6 +28,7 @@
#define HB_OT_POST_TABLE_HH
#include "hb-open-type-private.hh"
#include "hb-sort-r.hh"
#define HB_STRING_ARRAY_NAME format1_names
#define HB_STRING_ARRAY_LIST "hb-ot-post-macroman.hh"
......
......@@ -4,6 +4,31 @@
#include <hb-private.hh>
static inline void *
hb_bsearch_r(const void *key, const void *base,
size_t nmemb, size_t size,
int (*compar)(const void *_a, const void *_b, const void *_arg),
void *arg)
{
int min = 0, max = (int) nmemb - 1;
while (min <= max)
{
int mid = (min + max) / 2;
const void *p = (const void *) (((const char *) base) + (mid * size));
int c = compar (key, p, arg);
if (c < 0)
max = mid - 1;
else if (c > 0)
min = mid + 1;
else
return (void *) p;
}
return NULL;
}
/* From https://github.com/noporpoise/sort_r */
/*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册