[set] Add is_subset

New API:
+hb_set_is_subset()
This commit is contained in:
Behdad Esfahbod 2018-06-06 16:46:50 -07:00
parent 45186b9b8c
commit 11f1f4131b
5 changed files with 46 additions and 8 deletions

View File

@ -400,6 +400,19 @@ struct hb_set_t
return true; return true;
} }
inline bool is_subset (const hb_set_t *larger_set) const
{
if (get_population () > larger_set->get_population ())
return false;
hb_codepoint_t c = INVALID;
while (next (&c))
if (!larger_set->has (c))
return false;
return true;
}
template <class Op> template <class Op>
inline void process (const hb_set_t *other) inline void process (const hb_set_t *other)
{ {

View File

@ -267,11 +267,11 @@ hb_set_del_range (hb_set_t *set,
/** /**
* hb_set_is_equal: * hb_set_is_equal:
* @set: a set. * @set: a set.
* @other: * @other: other set.
* *
* *
* *
* Return value: * Return value: %TRUE if the two sets are equal, %FALSE otherwise.
* *
* Since: 0.9.7 * Since: 0.9.7
**/ **/
@ -282,6 +282,24 @@ hb_set_is_equal (const hb_set_t *set,
return set->is_equal (other); return set->is_equal (other);
} }
/**
* hb_set_is_subset:
* @set: a set.
* @larger_set: other set.
*
*
*
* Return value: %TRUE if the @set is a subset of (or equal to) @larger_set, %FALSE otherwise.
*
* Since: 1.8.1
**/
hb_bool_t
hb_set_is_subset (const hb_set_t *set,
const hb_set_t *larger_set)
{
return set->is_subset (larger_set);
}
/** /**
* hb_set_set: * hb_set_set:
* @set: a set. * @set: a set.

View File

@ -104,6 +104,10 @@ HB_EXTERN hb_bool_t
hb_set_is_equal (const hb_set_t *set, hb_set_is_equal (const hb_set_t *set,
const hb_set_t *other); const hb_set_t *other);
HB_EXTERN hb_bool_t
hb_set_is_subset (const hb_set_t *set,
const hb_set_t *larger_set);
HB_EXTERN void HB_EXTERN void
hb_set_set (hb_set_t *set, hb_set_set (hb_set_t *set,
const hb_set_t *other); const hb_set_t *other);

View File

@ -146,8 +146,12 @@ test_set_algebra (void)
test_empty (s); test_empty (s);
g_assert (!hb_set_is_equal (s, o)); g_assert (!hb_set_is_equal (s, o));
g_assert (hb_set_is_subset (s, o));
g_assert (!hb_set_is_subset (o, s));
hb_set_set (s, o); hb_set_set (s, o);
g_assert (hb_set_is_equal (s, o)); g_assert (hb_set_is_equal (s, o));
g_assert (hb_set_is_subset (s, o));
g_assert (hb_set_is_subset (o, s));
test_not_empty (s); test_not_empty (s);
g_assert_cmpint (hb_set_get_population (s), ==, 2); g_assert_cmpint (hb_set_get_population (s), ==, 2);

View File

@ -178,12 +178,11 @@ test_subset_glyf_strip_hints_invalid (void)
hb_set_t *codepoints = hb_set_create(); hb_set_t *codepoints = hb_set_create();
const hb_codepoint_t text[] = const hb_codepoint_t text[] =
{ {
'A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z', '1', '2', 'A', 'B', 'C', 'D', 'E', 'X', 'Y', 'Z', '1', '2',
'3', '@', '_', '%', '&', ')', '*', '$', '!' '3', '@', '_', '%', '&', ')', '*', '$', '!'
}; };
int i; for (unsigned int i = 0; i < sizeof (text) / sizeof (hb_codepoint_t); i++)
for (i = 0; i < sizeof (text) / sizeof (hb_codepoint_t); i++)
{ {
hb_set_add (codepoints, text[i]); hb_set_add (codepoints, text[i]);
// hb_set_add (codepoints_drop_hints, text[i]); // hb_set_add (codepoints_drop_hints, text[i]);