Commit 5d2dae9a authored by Daniel Buch Hansen's avatar Daniel Buch Hansen Committed by Christian Hergert

tree: introduce ide_tree_node_insert_sorted()

parent f0ac9544
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment