[bsearch] Massage API some more
This commit is contained in:
parent
70aa5071d8
commit
fa7edf87c9
|
@ -649,7 +649,7 @@ _hb_cmp_method (const void *pkey, const void *pval, Ts... ds)
|
||||||
|
|
||||||
template <typename V, typename K, typename ...Ts>
|
template <typename V, typename K, typename ...Ts>
|
||||||
static inline bool
|
static inline bool
|
||||||
hb_bsearch_impl (V** out,
|
hb_bsearch_impl (unsigned *pos, /* Out */
|
||||||
const K& key,
|
const K& key,
|
||||||
V* base, size_t nmemb, size_t stride,
|
V* base, size_t nmemb, size_t stride,
|
||||||
int (*compar)(const void *_key, const void *_item, Ts... _ds),
|
int (*compar)(const void *_key, const void *_item, Ts... _ds),
|
||||||
|
@ -672,14 +672,11 @@ hb_bsearch_impl (V** out,
|
||||||
min = mid + 1;
|
min = mid + 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*out = p;
|
*pos = mid;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic push
|
*pos = min;
|
||||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
|
||||||
*out = (V*) (((const char *) base) + (min * stride));
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -689,8 +686,12 @@ hb_bsearch (const K& key, V* base,
|
||||||
size_t nmemb, size_t stride = sizeof (V),
|
size_t nmemb, size_t stride = sizeof (V),
|
||||||
int (*compar)(const void *_key, const void *_item) = _hb_cmp_method<K, V>)
|
int (*compar)(const void *_key, const void *_item) = _hb_cmp_method<K, V>)
|
||||||
{
|
{
|
||||||
V* p;
|
unsigned pos;
|
||||||
return hb_bsearch_impl (&p, key, base, nmemb, stride, compar) ? p : nullptr;
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||||
|
return hb_bsearch_impl (&pos, key, base, nmemb, stride, compar) ?
|
||||||
|
(V*) (((const char *) base) + (pos * stride)) : nullptr;
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
}
|
}
|
||||||
template <typename V, typename K, typename ...Ts>
|
template <typename V, typename K, typename ...Ts>
|
||||||
static inline V*
|
static inline V*
|
||||||
|
@ -699,8 +700,12 @@ hb_bsearch (const K& key, V* base,
|
||||||
int (*compar)(const void *_key, const void *_item, Ts... _ds),
|
int (*compar)(const void *_key, const void *_item, Ts... _ds),
|
||||||
Ts... ds)
|
Ts... ds)
|
||||||
{
|
{
|
||||||
V* p;
|
unsigned pos;
|
||||||
return hb_bsearch_impl (&p, key, base, nmemb, stride, compar, ds...) ? p : nullptr;
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||||
|
return hb_bsearch_impl (&pos, key, base, nmemb, stride, compar, ds...) ?
|
||||||
|
(V*) (((const char *) base) + (pos * stride)) : nullptr;
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -297,19 +297,6 @@ struct hb_sorted_array_t :
|
||||||
return bfind (x, &i) ? &this->arrayZ[i] : not_found;
|
return bfind (x, &i) ? &this->arrayZ[i] : not_found;
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool bsearch_impl (const T &x, unsigned *pos) const
|
|
||||||
{
|
|
||||||
Type* p;
|
|
||||||
bool ret = hb_bsearch_impl (&p,
|
|
||||||
x,
|
|
||||||
this->arrayZ,
|
|
||||||
this->length,
|
|
||||||
sizeof (Type),
|
|
||||||
_hb_cmp_method<T, Type>);
|
|
||||||
*pos = p - this->arrayZ;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
template <typename T>
|
|
||||||
bool bfind (const T &x, unsigned int *i = nullptr,
|
bool bfind (const T &x, unsigned int *i = nullptr,
|
||||||
hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
|
hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
|
||||||
unsigned int to_store = (unsigned int) -1) const
|
unsigned int to_store = (unsigned int) -1) const
|
||||||
|
@ -341,6 +328,16 @@ struct hb_sorted_array_t :
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
template <typename T>
|
||||||
|
bool bsearch_impl (const T &x, unsigned *pos) const
|
||||||
|
{
|
||||||
|
return hb_bsearch_impl (pos,
|
||||||
|
x,
|
||||||
|
this->arrayZ,
|
||||||
|
this->length,
|
||||||
|
sizeof (Type),
|
||||||
|
_hb_cmp_method<T, Type>);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
template <typename T> inline hb_sorted_array_t<T>
|
template <typename T> inline hb_sorted_array_t<T>
|
||||||
hb_sorted_array (T *array, unsigned int length)
|
hb_sorted_array (T *array, unsigned int length)
|
||||||
|
|
Loading…
Reference in New Issue