Add hb_bsearch_r()
This commit is contained in:
parent
0712e915b4
commit
977679f229
|
@ -28,6 +28,7 @@
|
||||||
#define HB_OT_POST_TABLE_HH
|
#define HB_OT_POST_TABLE_HH
|
||||||
|
|
||||||
#include "hb-open-type-private.hh"
|
#include "hb-open-type-private.hh"
|
||||||
|
#include "hb-sort-r.hh"
|
||||||
|
|
||||||
#define HB_STRING_ARRAY_NAME format1_names
|
#define HB_STRING_ARRAY_NAME format1_names
|
||||||
#define HB_STRING_ARRAY_LIST "hb-ot-post-macroman.hh"
|
#define HB_STRING_ARRAY_LIST "hb-ot-post-macroman.hh"
|
||||||
|
|
|
@ -4,6 +4,31 @@
|
||||||
|
|
||||||
#include <hb-private.hh>
|
#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 */
|
/* From https://github.com/noporpoise/sort_r */
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue