mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
added new function g_tree_lookup_extended().
2001-03-08 Sven Neumann <sven@gimp.org> * gtree.[ch]: * docs/reference/glib/tmpl/trees-binary.sgml: added new function g_tree_lookup_extended().
This commit is contained in:
parent
9490f8d7e4
commit
e71a64bc86
@ -1,3 +1,9 @@
|
||||
2001-03-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gtree.[ch]:
|
||||
* docs/reference/glib/tmpl/trees-binary.sgml: added new function
|
||||
g_tree_lookup_extended().
|
||||
|
||||
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ghook.[hc]: destruction cleanup. there's one
|
||||
|
@ -1,3 +1,9 @@
|
||||
2001-03-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gtree.[ch]:
|
||||
* docs/reference/glib/tmpl/trees-binary.sgml: added new function
|
||||
g_tree_lookup_extended().
|
||||
|
||||
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ghook.[hc]: destruction cleanup. there's one
|
||||
|
@ -1,3 +1,9 @@
|
||||
2001-03-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gtree.[ch]:
|
||||
* docs/reference/glib/tmpl/trees-binary.sgml: added new function
|
||||
g_tree_lookup_extended().
|
||||
|
||||
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ghook.[hc]: destruction cleanup. there's one
|
||||
|
@ -1,3 +1,9 @@
|
||||
2001-03-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gtree.[ch]:
|
||||
* docs/reference/glib/tmpl/trees-binary.sgml: added new function
|
||||
g_tree_lookup_extended().
|
||||
|
||||
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ghook.[hc]: destruction cleanup. there's one
|
||||
|
@ -1,3 +1,9 @@
|
||||
2001-03-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gtree.[ch]:
|
||||
* docs/reference/glib/tmpl/trees-binary.sgml: added new function
|
||||
g_tree_lookup_extended().
|
||||
|
||||
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ghook.[hc]: destruction cleanup. there's one
|
||||
|
@ -1,3 +1,9 @@
|
||||
2001-03-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gtree.[ch]:
|
||||
* docs/reference/glib/tmpl/trees-binary.sgml: added new function
|
||||
g_tree_lookup_extended().
|
||||
|
||||
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ghook.[hc]: destruction cleanup. there's one
|
||||
|
@ -1,3 +1,9 @@
|
||||
2001-03-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gtree.[ch]:
|
||||
* docs/reference/glib/tmpl/trees-binary.sgml: added new function
|
||||
g_tree_lookup_extended().
|
||||
|
||||
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ghook.[hc]: destruction cleanup. there's one
|
||||
|
@ -1,3 +1,9 @@
|
||||
2001-03-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gtree.[ch]:
|
||||
* docs/reference/glib/tmpl/trees-binary.sgml: added new function
|
||||
g_tree_lookup_extended().
|
||||
|
||||
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* ghook.[hc]: destruction cleanup. there's one
|
||||
|
@ -17,7 +17,8 @@ To create a new #GTree use g_tree_new().
|
||||
To insert a key/value pair into a #GTree use g_tree_insert().
|
||||
</para>
|
||||
<para>
|
||||
To lookup the value corresponding to a given key, use g_tree_lookup().
|
||||
To lookup the value corresponding to a given key, use g_tree_lookup() and
|
||||
g_tree_lookup_extended().
|
||||
</para>
|
||||
<para>
|
||||
To find out the number of nodes in a #GTree, use g_tree_nnodes().
|
||||
@ -123,6 +124,22 @@ added, key lookup is very fast.
|
||||
@Returns: the value corresponding to the key.
|
||||
|
||||
|
||||
<!-- ##### FUNCTION g_tree_lookup_extended ##### -->
|
||||
<para>
|
||||
Gets the original key and the associated value and a gboolean which is
|
||||
TRUE if the key was found. This is useful if you need to free the memory
|
||||
allocated for the original key, for example before calling g_tree_remove().
|
||||
Since a #GTree is automatically balanced as key/value pairs are added,
|
||||
key lookup is very fast.
|
||||
</para>
|
||||
|
||||
@tree: a #GTree.
|
||||
@lookup_key: the key to look up.
|
||||
@orig_key: returns the original key.
|
||||
@value: returns the value associated with the key.
|
||||
@Returns: TRUE if the key was found in the #GTree.
|
||||
|
||||
|
||||
<!-- ##### FUNCTION g_tree_search ##### -->
|
||||
<para>
|
||||
Searches a #GTree using an alternative form of the comparison function.
|
||||
|
30
glib/gtree.c
30
glib/gtree.c
@ -238,6 +238,36 @@ g_tree_lookup (GTree *tree,
|
||||
rtree->key_compare_data, key);
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_tree_lookup_extended (GTree *tree,
|
||||
gconstpointer lookup_key,
|
||||
gpointer *orig_key,
|
||||
gpointer *value)
|
||||
{
|
||||
GRealTree *rtree;
|
||||
GTreeNode *node;
|
||||
|
||||
g_return_val_if_fail (tree != NULL, FALSE);
|
||||
|
||||
rtree = (GRealTree*) tree;
|
||||
|
||||
node = g_tree_node_lookup (rtree->root,
|
||||
rtree->key_compare,
|
||||
rtree->key_compare_data,
|
||||
lookup_key);
|
||||
|
||||
if (node)
|
||||
{
|
||||
if (orig_key)
|
||||
*orig_key = node->key;
|
||||
if (value)
|
||||
*value = node->value;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
g_tree_traverse (GTree *tree,
|
||||
GTraverseFunc traverse_func,
|
||||
|
@ -50,6 +50,10 @@ void g_tree_remove (GTree *tree,
|
||||
gconstpointer key);
|
||||
gpointer g_tree_lookup (GTree *tree,
|
||||
gconstpointer key);
|
||||
gboolean g_tree_lookup_extended (GTree *tree,
|
||||
gconstpointer lookup_key,
|
||||
gpointer *orig_key,
|
||||
gpointer *value);
|
||||
void g_tree_traverse (GTree *tree,
|
||||
GTraverseFunc traverse_func,
|
||||
GTraverseType traverse_type,
|
||||
|
30
gtree.c
30
gtree.c
@ -238,6 +238,36 @@ g_tree_lookup (GTree *tree,
|
||||
rtree->key_compare_data, key);
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_tree_lookup_extended (GTree *tree,
|
||||
gconstpointer lookup_key,
|
||||
gpointer *orig_key,
|
||||
gpointer *value)
|
||||
{
|
||||
GRealTree *rtree;
|
||||
GTreeNode *node;
|
||||
|
||||
g_return_val_if_fail (tree != NULL, FALSE);
|
||||
|
||||
rtree = (GRealTree*) tree;
|
||||
|
||||
node = g_tree_node_lookup (rtree->root,
|
||||
rtree->key_compare,
|
||||
rtree->key_compare_data,
|
||||
lookup_key);
|
||||
|
||||
if (node)
|
||||
{
|
||||
if (orig_key)
|
||||
*orig_key = node->key;
|
||||
if (value)
|
||||
*value = node->value;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
g_tree_traverse (GTree *tree,
|
||||
GTraverseFunc traverse_func,
|
||||
|
4
gtree.h
4
gtree.h
@ -50,6 +50,10 @@ void g_tree_remove (GTree *tree,
|
||||
gconstpointer key);
|
||||
gpointer g_tree_lookup (GTree *tree,
|
||||
gconstpointer key);
|
||||
gboolean g_tree_lookup_extended (GTree *tree,
|
||||
gconstpointer lookup_key,
|
||||
gpointer *orig_key,
|
||||
gpointer *value);
|
||||
void g_tree_traverse (GTree *tree,
|
||||
GTraverseFunc traverse_func,
|
||||
GTraverseType traverse_type,
|
||||
|
Loading…
Reference in New Issue
Block a user