[arrays] Port hb_vector_t.qsort() to hb_array_t's

This commit is contained in:
Behdad Esfahbod 2018-11-24 01:45:58 -05:00
parent e3face8e79
commit 61de55bf49
2 changed files with 15 additions and 11 deletions

View File

@ -572,6 +572,10 @@ struct hb_array_t
return arrayZ[i];
}
template <typename T> inline operator T * (void) const { return arrayZ; }
inline Type * operator & (void) const { return arrayZ; }
inline unsigned int get_size (void) const { return len * sizeof (Type); }
template <typename T>
@ -595,9 +599,15 @@ struct hb_array_t
return not_found;
}
template <typename T> inline operator T * (void) const { return arrayZ; }
inline Type * operator & (void) const { return arrayZ; }
inline void qsort (int (*cmp)(const void*, const void*))
{
::qsort (arrayZ, len, sizeof (Type), cmp);
}
inline void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1)
{
end = MIN (end, len);
::qsort (arrayZ + start, end - start, sizeof (Type), Type::cmp);
}
inline hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int seg_count) const
{

View File

@ -221,15 +221,9 @@ struct hb_vector_t
}
inline void qsort (int (*cmp)(const void*, const void*))
{
::qsort (arrayZ(), len, sizeof (Type), cmp);
}
{ as_array ().qsort (cmp); }
inline void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1)
{
end = MIN (end, len);
::qsort (arrayZ() + start, end - start, sizeof (Type), Type::cmp);
}
{ as_array ().qsort (start, end); }
template <typename T>
inline Type *lsearch (const T &x, Type *not_found = nullptr)