struct _GRealTree
{
GTreeNode *root;
- GCompareFuncData key_compare;
+ GCompareDataFunc key_compare;
gpointer key_compare_data;
};
gpointer value);
static void g_tree_node_destroy (GTreeNode *node);
static GTreeNode* g_tree_node_insert (GTreeNode *node,
- GCompareFuncData compare,
+ GCompareDataFunc compare,
gpointer comp_data,
gpointer key,
gpointer value,
gint *inserted);
static GTreeNode* g_tree_node_remove (GTreeNode *node,
- GCompareFuncData compare,
+ GCompareDataFunc compare,
gpointer comp_data,
gconstpointer key);
static GTreeNode* g_tree_node_balance (GTreeNode *node);
gint old_balance);
static GTreeNode* g_tree_node_restore_right_balance (GTreeNode *node,
gint old_balance);
-static gpointer g_tree_node_lookup (GTreeNode *node,
- GCompareFuncData compare,
+static GTreeNode* g_tree_node_lookup (GTreeNode *node,
+ GCompareDataFunc compare,
gpointer comp_data,
gconstpointer key);
static gint g_tree_node_count (GTreeNode *node);
}
}
-GTree* g_tree_new_udata(GCompareFuncData key_compare_func,
+GTree* g_tree_new_udata(GCompareDataFunc key_compare_func,
gpointer key_compare_data)
{
GRealTree *rtree;
GTree*
g_tree_new (GCompareFunc key_compare_func)
{
- return g_tree_new_udata ((GCompareFuncData) key_compare_func, NULL);
+ return g_tree_new_udata ((GCompareDataFunc) key_compare_func, NULL);
}
gconstpointer key)
{
GRealTree *rtree;
+ GTreeNode *node;
g_return_val_if_fail (tree != NULL, NULL);
rtree = (GRealTree*) tree;
- return g_tree_node_lookup (rtree->root, rtree->key_compare,
+ node = g_tree_node_lookup (rtree->root, rtree->key_compare,
rtree->key_compare_data, key);
+
+ return node ? node->value : NULL;
+}
+
+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
static GTreeNode*
g_tree_node_insert (GTreeNode *node,
- GCompareFuncData compare,
+ GCompareDataFunc compare,
gpointer compare_data,
gpointer key,
gpointer value,
static GTreeNode*
g_tree_node_remove (GTreeNode *node,
- GCompareFuncData compare,
+ GCompareDataFunc compare,
gpointer compare_data,
gconstpointer key)
{
return node;
}
-static gpointer
+static GTreeNode *
g_tree_node_lookup (GTreeNode *node,
- GCompareFuncData compare,
+ GCompareDataFunc compare,
gpointer compare_data,
gconstpointer key)
{
cmp = (* compare) (key, node->key, compare_data);
if (cmp == 0)
- return node->value;
+ return node;
if (cmp < 0)
{