set: Add a few useful functions

Allow to find out if a set is empty, and its
min and max.
This commit is contained in:
Matthias Clasen 2020-06-04 21:35:53 -04:00
parent 4fb50c7408
commit 06c34ce02f
2 changed files with 36 additions and 0 deletions

View File

@ -335,6 +335,38 @@ next_range:
return TRUE;
}
gboolean
gtk_set_is_empty (GtkSet *set)
{
return set->ranges->len == 0;
}
guint
gtk_set_get_min (GtkSet *set)
{
Range *r;
if (gtk_set_is_empty (set))
return 0;
r = &g_array_index (set->ranges, Range, 0);
return r->first;
}
guint
gtk_set_get_max (GtkSet *set)
{
Range *r;
if (gtk_set_is_empty (set))
return 0;
r = &g_array_index (set->ranges, Range, set->ranges->len - 1);
return r->first + r->n_items;
}
#if 0
void
gtk_set_dump (GtkSet *set)

View File

@ -67,4 +67,8 @@ void gtk_set_iter_init (GtkSetIter *iter,
gboolean gtk_set_iter_next (GtkSetIter *iter,
guint *item);
gboolean gtk_set_is_empty (GtkSet *set);
guint gtk_set_get_min (GtkSet *set);
guint gtk_set_get_max (GtkSet *set);
#endif /* __GTK_SET_H__ */