mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-15 14:50:06 +00:00
treeview: Add _gtk_rbtree_find_index()
Uses the parity to do an O(log N) search for the nth element in the tree in display order of the treeview.
This commit is contained in:
parent
59097ecef4
commit
635e53433d
@ -1104,6 +1104,56 @@ _gtk_rbtree_find_offset (GtkRBTree *tree,
|
|||||||
return _gtk_rbtree_real_find_offset (tree, height, new_tree, new_node);
|
return _gtk_rbtree_real_find_offset (tree, height, new_tree, new_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_gtk_rbtree_find_index (GtkRBTree *tree,
|
||||||
|
guint index,
|
||||||
|
GtkRBTree **new_tree,
|
||||||
|
GtkRBNode **new_node)
|
||||||
|
{
|
||||||
|
GtkRBNode *tmp_node;
|
||||||
|
|
||||||
|
g_assert (tree);
|
||||||
|
|
||||||
|
tmp_node = tree->root;
|
||||||
|
while (tmp_node != tree->nil)
|
||||||
|
{
|
||||||
|
if (tmp_node->left->total_count > index)
|
||||||
|
{
|
||||||
|
tmp_node = tmp_node->left;
|
||||||
|
}
|
||||||
|
else if (tmp_node->total_count - tmp_node->right->total_count <= index)
|
||||||
|
{
|
||||||
|
index -= tmp_node->total_count - tmp_node->right->total_count;
|
||||||
|
tmp_node = tmp_node->right;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index -= tmp_node->left->total_count;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tmp_node == tree->nil)
|
||||||
|
{
|
||||||
|
*new_tree = NULL;
|
||||||
|
*new_node = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index > 0)
|
||||||
|
{
|
||||||
|
g_assert (tmp_node->children);
|
||||||
|
|
||||||
|
return _gtk_rbtree_find_index (tmp_node->children,
|
||||||
|
index - 1,
|
||||||
|
new_tree,
|
||||||
|
new_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
*new_tree = tree;
|
||||||
|
*new_node = tmp_node;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_gtk_rbtree_remove_node (GtkRBTree *tree,
|
_gtk_rbtree_remove_node (GtkRBTree *tree,
|
||||||
GtkRBNode *node)
|
GtkRBNode *node)
|
||||||
|
@ -135,6 +135,10 @@ gint _gtk_rbtree_node_find_offset (GtkRBTree *tree,
|
|||||||
GtkRBNode *node);
|
GtkRBNode *node);
|
||||||
gint _gtk_rbtree_node_find_parity (GtkRBTree *tree,
|
gint _gtk_rbtree_node_find_parity (GtkRBTree *tree,
|
||||||
GtkRBNode *node);
|
GtkRBNode *node);
|
||||||
|
gboolean _gtk_rbtree_find_index (GtkRBTree *tree,
|
||||||
|
guint index,
|
||||||
|
GtkRBTree **new_tree,
|
||||||
|
GtkRBNode **new_node);
|
||||||
gint _gtk_rbtree_find_offset (GtkRBTree *tree,
|
gint _gtk_rbtree_find_offset (GtkRBTree *tree,
|
||||||
gint offset,
|
gint offset,
|
||||||
GtkRBTree **new_tree,
|
GtkRBTree **new_tree,
|
||||||
|
Loading…
Reference in New Issue
Block a user