Merge pull request #3386 from harfbuzz/unify-sorted-vector
Unify sorted vector
This commit is contained in:
commit
cfa00238e4
|
@ -447,23 +447,29 @@ struct
|
|||
private:
|
||||
|
||||
template <typename T1, typename T2> auto
|
||||
impl (T1&& v1, T2 &&v2, hb_priority<2>) const HB_AUTO_RETURN
|
||||
impl (T1&& v1, T2 &&v2, hb_priority<3>) const HB_AUTO_RETURN
|
||||
(
|
||||
std::forward<T2> (v2).cmp (std::forward<T1> (v1)) == 0
|
||||
)
|
||||
|
||||
template <typename T1, typename T2> auto
|
||||
impl (T1&& v1, T2 &&v2, hb_priority<1>) const HB_AUTO_RETURN
|
||||
impl (T1&& v1, T2 &&v2, hb_priority<2>) const HB_AUTO_RETURN
|
||||
(
|
||||
std::forward<T1> (v1).cmp (std::forward<T2> (v2)) == 0
|
||||
)
|
||||
|
||||
template <typename T1, typename T2> auto
|
||||
impl (T1&& v1, T2 &&v2, hb_priority<0>) const HB_AUTO_RETURN
|
||||
impl (T1&& v1, T2 &&v2, hb_priority<1>) const HB_AUTO_RETURN
|
||||
(
|
||||
std::forward<T1> (v1) == std::forward<T2> (v2)
|
||||
)
|
||||
|
||||
template <typename T1, typename T2> auto
|
||||
impl (T1&& v1, T2 &&v2, hb_priority<0>) const HB_AUTO_RETURN
|
||||
(
|
||||
std::forward<T2> (v2) == std::forward<T1> (v1)
|
||||
)
|
||||
|
||||
public:
|
||||
|
||||
template <typename T1, typename T2> auto
|
||||
|
|
|
@ -481,8 +481,8 @@ struct active_feature_t {
|
|||
a->rec.setting < b->rec.setting ? -1 : a->rec.setting > b->rec.setting ? 1 :
|
||||
0;
|
||||
}
|
||||
bool operator== (const active_feature_t *f) {
|
||||
return cmp (this, f) == 0;
|
||||
bool operator== (const active_feature_t& f) const {
|
||||
return cmp (this, &f) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -677,7 +677,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
|
|||
{
|
||||
active_features.push (event->feature);
|
||||
} else {
|
||||
active_feature_t *feature = active_features.find (&event->feature);
|
||||
active_feature_t *feature = active_features.lsearch (event->feature);
|
||||
if (feature)
|
||||
active_features.remove (feature - active_features.arrayZ);
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ hb_ms_setup_features (const hb_feature_t *features,
|
|||
}
|
||||
else
|
||||
{
|
||||
auto *feature = active_features.find (&event->feature);
|
||||
auto *feature = active_features.lsearch (event->feature);
|
||||
if (feature)
|
||||
active_features.remove (feature - active_features.arrayZ);
|
||||
}
|
||||
|
|
|
@ -52,8 +52,8 @@ struct hb_ms_active_feature_t {
|
|||
a->fea.value < b->fea.value ? -1 : a->fea.value > b->fea.value ? 1 :
|
||||
0;
|
||||
}
|
||||
bool operator== (const hb_ms_active_feature_t *f)
|
||||
{ return cmp (this, f) == 0; }
|
||||
bool operator== (const hb_ms_active_feature_t f) const
|
||||
{ return cmp (this, &f) == 0; }
|
||||
};
|
||||
|
||||
struct hb_ms_feature_event_t {
|
||||
|
|
|
@ -53,7 +53,7 @@ struct hb_lockable_set_t
|
|||
item_t *replace_or_insert (T v, lock_t &l, bool replace)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
item_t *item = items.lsearch (v);
|
||||
if (item) {
|
||||
if (replace) {
|
||||
item_t old = *item;
|
||||
|
@ -76,7 +76,7 @@ struct hb_lockable_set_t
|
|||
void remove (T v, lock_t &l)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
item_t *item = items.lsearch (v);
|
||||
if (item)
|
||||
{
|
||||
item_t old = *item;
|
||||
|
@ -93,7 +93,7 @@ struct hb_lockable_set_t
|
|||
bool find (T v, item_t *i, lock_t &l)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
item_t *item = items.lsearch (v);
|
||||
if (item)
|
||||
*i = *item;
|
||||
l.unlock ();
|
||||
|
|
|
@ -32,11 +32,14 @@
|
|||
#include "hb-null.hh"
|
||||
|
||||
|
||||
template <typename Type>
|
||||
struct hb_vector_t
|
||||
template <typename Type,
|
||||
bool sorted=false>
|
||||
struct hb_vector_t : std::conditional<sorted, hb_vector_t<Type, false>, hb_empty_t>::type
|
||||
{
|
||||
typedef Type item_t;
|
||||
static constexpr unsigned item_size = hb_static_size (Type);
|
||||
using array_t = typename std::conditional<sorted, hb_sorted_array_t<Type>, hb_array_t<Type>>::type;
|
||||
using c_array_t = typename std::conditional<sorted, hb_sorted_array_t<const Type>, hb_array_t<const Type>>::type;
|
||||
|
||||
hb_vector_t () = default;
|
||||
hb_vector_t (std::initializer_list<Type> lst) : hb_vector_t ()
|
||||
|
@ -146,24 +149,24 @@ struct hb_vector_t
|
|||
template <typename T>
|
||||
hb_vector_t& operator << (T&& v) { push (std::forward<T> (v)); return *this; }
|
||||
|
||||
hb_array_t< Type> as_array () { return hb_array (arrayZ, length); }
|
||||
hb_array_t<const Type> as_array () const { return hb_array (arrayZ, length); }
|
||||
array_t as_array () { return hb_array (arrayZ, length); }
|
||||
c_array_t as_array () const { return hb_array (arrayZ, length); }
|
||||
|
||||
/* Iterator. */
|
||||
typedef hb_array_t<const Type> iter_t;
|
||||
typedef hb_array_t< Type> writer_t;
|
||||
typedef c_array_t iter_t;
|
||||
typedef array_t writer_t;
|
||||
iter_t iter () const { return as_array (); }
|
||||
writer_t writer () { return as_array (); }
|
||||
operator iter_t () const { return iter (); }
|
||||
operator writer_t () { return writer (); }
|
||||
|
||||
hb_array_t<const Type> sub_array (unsigned int start_offset, unsigned int count) const
|
||||
c_array_t sub_array (unsigned int start_offset, unsigned int count) const
|
||||
{ return as_array ().sub_array (start_offset, count); }
|
||||
hb_array_t<const Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) const
|
||||
c_array_t sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) const
|
||||
{ return as_array ().sub_array (start_offset, count); }
|
||||
hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int count)
|
||||
array_t sub_array (unsigned int start_offset, unsigned int count)
|
||||
{ return as_array ().sub_array (start_offset, count); }
|
||||
hb_array_t<Type> sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */)
|
||||
array_t sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */)
|
||||
{ return as_array ().sub_array (start_offset, count); }
|
||||
|
||||
hb_sorted_array_t<Type> as_sorted_array ()
|
||||
|
@ -362,28 +365,14 @@ struct hb_vector_t
|
|||
shrink_vector (size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Type *find (T v)
|
||||
{
|
||||
for (unsigned int i = 0; i < length; i++)
|
||||
if (arrayZ[i] == v)
|
||||
return &arrayZ[i];
|
||||
return nullptr;
|
||||
}
|
||||
template <typename T>
|
||||
const Type *find (T v) const
|
||||
{
|
||||
for (unsigned int i = 0; i < length; i++)
|
||||
if (arrayZ[i] == v)
|
||||
return &arrayZ[i];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Sorting API. */
|
||||
void qsort (int (*cmp)(const void*, const void*))
|
||||
{ as_array ().qsort (cmp); }
|
||||
void qsort (unsigned int start = 0, unsigned int end = (unsigned int) -1)
|
||||
{ as_array ().qsort (start, end); }
|
||||
|
||||
/* Unsorted search API. */
|
||||
template <typename T>
|
||||
Type *lsearch (const T &x, Type *not_found = nullptr)
|
||||
{ return as_array ().lsearch (x, not_found); }
|
||||
|
@ -393,47 +382,25 @@ struct hb_vector_t
|
|||
template <typename T>
|
||||
bool lfind (const T &x, unsigned *pos = nullptr) const
|
||||
{ return as_array ().lfind (x, pos); }
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
struct hb_sorted_vector_t : hb_vector_t<Type>
|
||||
{
|
||||
hb_sorted_vector_t () = default;
|
||||
~hb_sorted_vector_t () = default;
|
||||
hb_sorted_vector_t (hb_sorted_vector_t& o) = default;
|
||||
hb_sorted_vector_t (hb_sorted_vector_t &&o) = default;
|
||||
hb_sorted_vector_t (std::initializer_list<Type> lst) : hb_vector_t<Type> (lst) {}
|
||||
template <typename Iterable,
|
||||
hb_requires (hb_is_iterable (Iterable))>
|
||||
hb_sorted_vector_t (const Iterable &o) : hb_vector_t<Type> (o) {}
|
||||
hb_sorted_vector_t& operator = (const hb_sorted_vector_t &o) = default;
|
||||
hb_sorted_vector_t& operator = (hb_sorted_vector_t &&o) = default;
|
||||
friend void swap (hb_sorted_vector_t& a, hb_sorted_vector_t& b)
|
||||
{ hb_swap ((hb_vector_t<Type>&) (a), (hb_vector_t<Type>&) (b)); }
|
||||
|
||||
hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ, this->length); }
|
||||
hb_sorted_array_t<const Type> as_array () const { return hb_sorted_array (this->arrayZ, this->length); }
|
||||
|
||||
/* Iterator. */
|
||||
typedef hb_sorted_array_t<const Type> const_iter_t;
|
||||
typedef hb_sorted_array_t< Type> iter_t;
|
||||
const_iter_t iter () const { return as_array (); }
|
||||
const_iter_t citer () const { return as_array (); }
|
||||
iter_t iter () { return as_array (); }
|
||||
operator iter_t () { return iter (); }
|
||||
operator const_iter_t () const { return iter (); }
|
||||
|
||||
template <typename T>
|
||||
/* Sorted search API. */
|
||||
template <typename T,
|
||||
bool Sorted=sorted, hb_enable_if (Sorted)>
|
||||
Type *bsearch (const T &x, Type *not_found = nullptr)
|
||||
{ return as_array ().bsearch (x, not_found); }
|
||||
template <typename T>
|
||||
template <typename T,
|
||||
bool Sorted=sorted, hb_enable_if (Sorted)>
|
||||
const Type *bsearch (const T &x, const Type *not_found = nullptr) const
|
||||
{ return as_array ().bsearch (x, not_found); }
|
||||
template <typename T>
|
||||
template <typename T,
|
||||
bool Sorted=sorted, hb_enable_if (Sorted)>
|
||||
bool bfind (const T &x, unsigned int *i = nullptr,
|
||||
hb_not_found_t not_found = HB_NOT_FOUND_DONT_STORE,
|
||||
unsigned int to_store = (unsigned int) -1) const
|
||||
{ return as_array ().bfind (x, i, not_found, to_store); }
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
using hb_sorted_vector_t = hb_vector_t<Type, true>;
|
||||
|
||||
#endif /* HB_VECTOR_HH */
|
||||
|
|
Loading…
Reference in New Issue