[gtk+] rbtree: Add _gtk_rbtree_contains()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] rbtree: Add _gtk_rbtree_contains()
- Date: Sat, 10 Dec 2011 07:00:45 +0000 (UTC)
commit 710a8435cce5511d8e7d0e441e3a079122076a6a
Author: Benjamin Otte <otte redhat com>
Date: Sat Dec 10 02:02:29 2011 +0100
rbtree: Add _gtk_rbtree_contains()
It's useful in a bunch of places, so split it out
gtk/gtkrbtree.c | 25 +++++++++++++++++++++++++
gtk/gtkrbtree.h | 2 ++
2 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkrbtree.c b/gtk/gtkrbtree.c
index d6dc938..1b6d7f5 100644
--- a/gtk/gtkrbtree.c
+++ b/gtk/gtkrbtree.c
@@ -880,6 +880,31 @@ _gtk_rbtree_reorder (GtkRBTree *tree,
g_free (nodes);
}
+/**
+ * _gtk_rbtree_contains:
+ * @tree: a tree
+ * @potential_child: a potential child of @tree
+ *
+ * Checks if @potential_child is a child (direct or via intermediate
+ * trees) of @tree.
+ *
+ * Returns: %TRUE if @potentitial_child is a child of @tree.
+ **/
+gboolean
+_gtk_rbtree_contains (GtkRBTree *tree,
+ GtkRBTree *potential_child)
+{
+ g_return_val_if_fail (tree != NULL, FALSE);
+ g_return_val_if_fail (potential_child != NULL, FALSE);
+
+ do {
+ potential_child = potential_child->parent_tree;
+ if (potential_child == tree)
+ return TRUE;
+ } while (potential_child != NULL);
+
+ return FALSE;
+}
gint
_gtk_rbtree_node_find_offset (GtkRBTree *tree,
diff --git a/gtk/gtkrbtree.h b/gtk/gtkrbtree.h
index 173b141..931f7c6 100644
--- a/gtk/gtkrbtree.h
+++ b/gtk/gtkrbtree.h
@@ -117,6 +117,8 @@ gboolean _gtk_rbtree_is_nil (GtkRBNode *node);
void _gtk_rbtree_reorder (GtkRBTree *tree,
gint *new_order,
gint length);
+gboolean _gtk_rbtree_contains (GtkRBTree *tree,
+ GtkRBTree *potential_child);
GtkRBNode *_gtk_rbtree_find_count (GtkRBTree *tree,
gint count);
void _gtk_rbtree_node_set_height (GtkRBTree *tree,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]