[gnome-builder] tree: introduce ide_tree_node_insert_sorted()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] tree: introduce ide_tree_node_insert_sorted()
- Date: Tue, 15 Jan 2019 21:25:28 +0000 (UTC)
commit 5d2dae9ac0742c816f85ac740187426dca7f6b74
Author: Daniel Buch <boogiewasthere gmail com>
Date: Tue Jan 15 21:18:59 2019 +0100
tree: introduce ide_tree_node_insert_sorted()
src/libide/tree/ide-tree-node.c | 31 +++++++++++++++++++++++++++++++
src/libide/tree/ide-tree-node.h | 20 ++++++++++++++++++++
2 files changed, 51 insertions(+)
---
diff --git a/src/libide/tree/ide-tree-node.c b/src/libide/tree/ide-tree-node.c
index aeda3c25b..6ef03280c 100644
--- a/src/libide/tree/ide-tree-node.c
+++ b/src/libide/tree/ide-tree-node.c
@@ -808,6 +808,37 @@ ide_tree_node_append (IdeTreeNode *self,
ide_tree_node_row_inserted (self, child);
}
+/**
+ * ide_tree_node_insert_sorted:
+ * @self: an #IdeTreeNode
+ * @child: an #IdeTreeNode
+ * @cmpfn: (scope call): an #IdeTreeNodeCompare
+ *
+ * Insert @child as a child of @self at the sorted position determined by @cmpfn
+ *
+ * This operation is O(n).
+ *
+ * Since: 3.32
+ */
+void
+ide_tree_node_insert_sorted (IdeTreeNode *self,
+ IdeTreeNode *child,
+ IdeTreeNodeCompare cmpfn)
+{
+ GList *link;
+
+ g_return_if_fail (IDE_IS_TREE_NODE (self));
+ g_return_if_fail (IDE_IS_TREE_NODE (child));
+ g_return_if_fail (child->parent == NULL);
+
+ link = g_queue_find_custom (&self->children, child, (GCompareFunc)cmpfn);
+
+ if (link != NULL)
+ ide_tree_node_insert_before (IDE_TREE_NODE (link->data), child);
+ else
+ ide_tree_node_append (self, child);
+}
+
/**
* ide_tree_node_insert_before:
* @self: a #IdeTreeNode
diff --git a/src/libide/tree/ide-tree-node.h b/src/libide/tree/ide-tree-node.h
index 2a0339dd2..02ce2cb5a 100644
--- a/src/libide/tree/ide-tree-node.h
+++ b/src/libide/tree/ide-tree-node.h
@@ -50,6 +50,22 @@ typedef enum
typedef IdeTreeNodeVisit (*IdeTreeTraverseFunc) (IdeTreeNode *node,
gpointer user_data);
+
+/**
+ * IdeTreeNodeCompare:
+ * @node: an #IdeTreeNode that iterate over children
+ * @child: an #IdeTreeNode to be inserted
+ *
+
+ * This callback function is a convenience wrapper around GCompareFunc
+ *
+ * Returns: int
+ *
+ * Since: 3.32
+ */
+typedef int (*IdeTreeNodeCompare) (IdeTreeNode *node,
+ IdeTreeNode *child);
+
IDE_AVAILABLE_IN_3_32
IdeTreeNode *ide_tree_node_new (void);
IDE_AVAILABLE_IN_3_32
@@ -120,6 +136,10 @@ IDE_AVAILABLE_IN_3_32
void ide_tree_node_append (IdeTreeNode *self,
IdeTreeNode *child);
IDE_AVAILABLE_IN_3_32
+void ide_tree_node_insert_sorted (IdeTreeNode *self,
+ IdeTreeNode *child,
+ IdeTreeNodeCompare cmpfn);
+IDE_AVAILABLE_IN_3_32
void ide_tree_node_insert_before (IdeTreeNode *self,
IdeTreeNode *child);
IDE_AVAILABLE_IN_3_32
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]