[gtk/rubberband-again: 1/3] set: Add a few useful functions
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/rubberband-again: 1/3] set: Add a few useful functions
- Date: Fri, 5 Jun 2020 02:32:07 +0000 (UTC)
commit 06c34ce02f7b9b549a97082bd7e7e160767f16d7
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jun 4 21:35:53 2020 -0400
set: Add a few useful functions
Allow to find out if a set is empty, and its
min and max.
gtk/gtkset.c | 32 ++++++++++++++++++++++++++++++++
gtk/gtkset.h | 4 ++++
2 files changed, 36 insertions(+)
---
diff --git a/gtk/gtkset.c b/gtk/gtkset.c
index 69f1dea72e..b4e0ae7627 100644
--- a/gtk/gtkset.c
+++ b/gtk/gtkset.c
@@ -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)
diff --git a/gtk/gtkset.h b/gtk/gtkset.h
index d0ba4e1a96..1ab6c6d1a2 100644
--- a/gtk/gtkset.h
+++ b/gtk/gtkset.h
@@ -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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]